真的很简单!首先,你必须将图像插入到html。完成这一步后,您必须添加一个数据属性- data-slideshow并设置其值的路径的一系列图像:剩下的,就是我们的插件引用在您的页面,调用它的slideShow()方法和你的幻灯片!插件包括一个JavaScript文件和一个CSS。我们将开始js文件!assets/jQuery-slideshow-plugin/plugin.js这个文件是普通jQuery插件。首先我们需要定义默认选项。options = $.extend({ timeOut: 3000, // how long each slide stays on screen showNavigation: true, // show previous/next arrows pauseOnHover: true, // pause when hovering with the mouse swipeNavigation: true // (basic) support for swipe gestures}, options);基本的想法是,我们采取某种形象的来源从data-slideshow属性,并将它们插入到一个div作为它的背景。这个div原始图片的尺寸和后收集的所有图像幻灯片(包括我们开始一个)取代它。让我们来看看代码使其更清晰一点。// Variablesvar intervals = [], slideshowImgs = [], originalSrc, img, cont, width, height,// Creates an object with all the elements with a "data-slideshow" attributecontainer = this.filter(function () { return $(this).data("slideshow");});// Cycle through all the elements from the container object// Later on we"ll use the "i" variable to distinguish the separate slideshows from one anotherfor (var i = 0; i < container.length; i++) { cont = $(container[i]); width = container.eq(i).outerWidth(true); height = container.eq(i).outerHeight(true); // For every separate slideshow, a helper
简单的jQuery幻灯片图片轮播插件
最新推荐文章于 2022-12-26 13:18:41 发布
, each with its own ID. // In those we"ll store the images for our slides. var helpdiv = $("
"); helpdiv.height(height); helpdiv.width(width); // If this option is enabled, call a function that appends buttons if (options.showNavigation) { Navigation(); } // Append the original image to the helper
originalSrc = cont.attr("src"); img = $("