jQuery插件animateSlide制作多点滑动幻灯片_jquery
首页banner的酷炫效果多来自全屏大图的幻灯片动画,下面提供一种完美兼容的jquery动画特效:全新jquery多点滑动幻灯片——全屏动画animateSlide(代码完全原创)。
直接上代码,把html、css和jquery代码copy到页面上即可呈现完美画面。
html代码如下:
<div class="animateSlide"> <div class="animateSlideImgWrap"> <div class="animateSlideImgBox present"> <p class="text1">亲,这是第一行标题</p> <p class="text2">AAAAAAAAAAAAAAAAAAAAA</p> <!--<img class="img lazy" src="/static/imghw/default1.png" data-src="img/1.png" alt="" />--> <div class="img" style="width: 500px; height: 390px; background: #ffaeae; opacity: 0.6;"></div><!-- 实际项目中用上面注释的半透明png图片,目前临时用div代替图片 --> </div> <div class="animateSlideImgBox"> <p class="text1">亲,这是一行宣传语</p> <p class="text2">BBBBBBBBBBBBBBBBBBBBB</p> <!--<img class="img lazy" src="/static/imghw/default1.png" data-src="img/2.png" alt="" />--> <div class="img" style="width: 500px; height: 390px; background: #aeffb2; opacity: 0.6;"></div><!-- 实际项目中用上面注释的半透明png图片,目前临时用div代替图片 --> </div> <div class="animateSlideImgBox"> <p class="text1">亲,这是一个奇迹啊</p> <p class="text2">CCCCCCCCCCCCCCCCCCCCC</p> <!--<img class="img lazy" src="/static/imghw/default1.png" data-src="img/3.png" alt="" />--> <div class="img" style="width: 500px; height: 390px; background: #aebdff; opacity: 0.6;"></div><!-- 实际项目中用上面注释的半透明png图片,目前临时用div代替图片 --> </div> </div> <div class="animateSlideBtnL"><</div> <div class="animateSlideBtnR"><</div> </div>
css代码如下:
.animateSlide {width: 100%; height: 390px; position: relative; background: #f5f5f5;} .animateSlideImgWrap {width: 100%; height: 390px; position: absolute; z-index: 1; overflow: hidden;} .animateSlideImgWrap .present {display: block;} .animateSlideImgBox {width: 100%; height: 390px; position: absolute; z-index: 1; display: none;} .animateSlideImgBox .text1 {font-family: Microsoft YaHei; font-size: 36px; line-height: 1.2em; color: #384cd0; position: absolute; top: 120px; z-index: 3; white-space: nowrap;} .animateSlideImgBox .text2 {font-family: Microsoft YaHei; font-size: 26px; line-height: 1.2em; color: orange; position: absolute; top: 200px; z-index: 3; white-space: nowrap;} .animateSlideImgBox .img {position: absolute; left: 470px; top: 0; z-index: 2;} .animateSlideBtnL, .animateSlideBtnR { width: 30px; height: 60px; line-height: 60px; font-size: 20px; font-weight: 700; text-align: center; background: #ddd; position: absolute; left: 30px; top: 150px; z-index: 6; cursor: pointer; display: none; } .animateSlideBtnR {left: auto; right: 20px;}
jquery代码如下:
(function($) { $.fn.animateSlide = function(options) { var defaults = { btnL: ".animateSlideBtnL", btnR: ".animateSlideBtnR", imgBox: ".animateSlideImgBox", animateTime: 500, delayTime: 5000, density: 1 }; var opts = $.extend(defaults, options); var widthWin = $(window).width(); $(window).resize(function() { widthWin = $(window).width(); }); // this.on("mouseenter", function() { $(this).find(".animateSlideBtnL, .animateSlideBtnR").stop().fadeIn(400); }).on("mouseleave", function() { $(this).find(".animateSlideBtnL, .animateSlideBtnR").stop().fadeOut(400); }); return this.each(function() { var _this = $(this); var _btnL = _this.find(opts.btnL); var _btnR = _this.find(opts.btnR); var _imgBox = _this.find(opts.imgBox); var _imgBoxCur = _imgBox.filter(".present"); var _curText1 = _imgBoxCur.find(".text1"), _curText2 = _imgBoxCur.find(".text2"), _curImg = _imgBoxCur.find(".img"); var _imgBoxNext = null, _nextText1 = null, _nextText2 = null, _nextImg = null; var index = _imgBox.index(_imgBoxCur) || 0; var size = _imgBox.size(); var start = null; index++; if(index >= size) { index = 0; } _imgBoxNext = _imgBox.eq(index); _nextText1 = _imgBoxNext.find(".text1"); _nextText2 = _imgBoxNext.find(".text2"); _nextImg = _imgBoxNext.find(".img"); _imgBox.find(".text1, .text2, .img").css("left", widthWin); _imgBoxCur.find(".text1, .text2").css("left", (widthWin - 980) / 2 + "px"); _imgBoxCur.find(".img").css("left", (widthWin - 980) / 2 + 470 + "px"); _btnR.on("click", function() { animateSlideFn(); }); _btnL.on("click", function() { animateSlideFn(); }); start = setTimeout(function() { animateSlideFn(); start = setTimeout(arguments.callee, opts.delayTime); }, opts.delayTime); function animateSlideFn() { if(!(_imgBoxCur.find(".text1, .text2, .img").is(":animated") || _imgBoxNext.find(".text1, .text2, .img").is(":animated"))) { //当前帧动画 _curText1.animate({ left: parseInt(_curText1.css("left")) + 100 }, opts.animateTime * 0.6, function() { _curText1.animate({ left: "-510px" }, opts.animateTime); }); setTimeout(function() { _curText2.animate({ left: parseInt(_curText2.css("left")) + 100 }, opts.animateTime * 0.6, function() { _curText2.animate({ left: "-510px" }, opts.animateTime); }); }, 200); setTimeout(function() { _curImg.animate({ left: parseInt(_curImg.css("left")) + 200 }, opts.animateTime * 0.6, function() { _curImg.animate({ left: "-510px" }, opts.animateTime, function() { _imgBox.find(".text1, .text2, .img").css("left", widthWin); _imgBoxCur.removeClass("present"); }); }); }, 400); //下一帧动画 setTimeout(function() { _imgBoxNext.addClass("present"); _nextText1.animate({ left: (widthWin - 980) / 2 - 100 }, opts.animateTime, function() { _nextText1.animate({ left: (widthWin - 980) / 2 }, opts.animateTime * 0.6); }); setTimeout(function() { _nextText2.animate({ left: (widthWin - 980) / 2 - 100 }, opts.animateTime, function() { _nextText2.animate({ left: (widthWin - 980) / 2 }, opts.animateTime * 0.6); }); }, 200); setTimeout(function() { _nextImg.animate({ left: (widthWin - 980) / 2 + 370 }, opts.animateTime, function() { _nextImg.animate({ left: (widthWin - 980) / 2 + 470 }, opts.animateTime * 0.6, function() { index++; if(index >= size) { index = 0; } _imgBoxCur = _imgBox.filter(".present"); _imgBoxNext = _imgBox.eq(index); _curText1 = _imgBoxCur.find(".text1"); _curText2 = _imgBoxCur.find(".text2"); _curImg = _imgBoxCur.find(".img"); _nextText1 = _imgBoxNext.find(".text1"); _nextText2 = _imgBoxNext.find(".text2"); _nextImg = _imgBoxNext.find(".img"); }); }); }, 400); }, opts.density * 1200); } } }); }; })(jQuery); $(function() { $(".animateSlide").animateSlide({ btnL: ".animateSlideBtnL", btnR: ".animateSlideBtnR", imgBox: ".animateSlideImgBox", animateTime: 500, delayTime: 6000, density: 0.9 }); });

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

jQuery引用方法详解:快速上手指南jQuery是一个流行的JavaScript库,被广泛用于网站开发中,它简化了JavaScript编程,并为开发者提供了丰富的功能和特性。本文将详细介绍jQuery的引用方法,并提供具体的代码示例,帮助读者快速上手。引入jQuery首先,我们需要在HTML文件中引入jQuery库。可以通过CDN链接的方式引入,也可以下载

jQuery中如何使用PUT请求方式?在jQuery中,发送PUT请求的方法与发送其他类型的请求类似,但需要注意一些细节和参数设置。PUT请求通常用于更新资源,例如更新数据库中的数据或更新服务器上的文件。以下是在jQuery中使用PUT请求方式的具体代码示例。首先,确保引入了jQuery库文件,然后可以通过以下方式发送PUT请求:$.ajax({u

jQuery是一款广泛应用于前端开发的快速、小巧、功能丰富的JavaScript库。自2006年发布以来,jQuery已经成为众多开发者的首选工具之一,但是在实际应用中,它也不乏一些优势和劣势。本文将深度剖析jQuery的优势与劣势,并结合具体的代码示例进行说明。优势:1.简洁的语法jQuery的语法设计简洁明了,可以大大提高代码的可读性和编写效率。比如,

jQuery如何移除元素的height属性?在前端开发中,经常会遇到需要操作元素的高度属性的需求。有时候,我们可能需要动态改变元素的高度,而有时候又需要移除元素的高度属性。本文将介绍如何使用jQuery来移除元素的高度属性,并提供具体的代码示例。在使用jQuery操作高度属性之前,我们首先需要了解CSS中的height属性。height属性用于设置元素的高度

标题:jQuery小技巧:快速修改页面所有a标签的文本在网页开发中,我们经常需要对页面中的元素进行修改和操作。在使用jQuery时,有时候需要一次性修改页面中所有a标签的文本内容,这样可以节省时间和精力。下面将介绍如何使用jQuery快速修改页面所有a标签的文本,同时给出具体的代码示例。首先,我们需要引入jQuery库文件,确保在页面中引入了以下代码:<

标题:使用jQuery修改所有a标签的文本内容jQuery是一款流行的JavaScript库,被广泛用于处理DOM操作。在网页开发中,经常会遇到需要修改页面上链接标签(a标签)的文本内容的需求。本文将介绍如何使用jQuery来实现这个目标,并提供具体的代码示例。首先,我们需要在页面中引入jQuery库。在HTML文件中添加以下代码:

jQuery是一种流行的JavaScript库,被广泛用于处理网页中的DOM操作和事件处理。在jQuery中,eq()方法是用来选择指定索引位置的元素的方法,具体使用方法和应用场景如下。在jQuery中,eq()方法选择指定索引位置的元素。索引位置从0开始计数,即第一个元素的索引是0,第二个元素的索引是1,依此类推。eq()方法的语法如下:$("s

如何判断jQuery元素是否具有特定属性?在使用jQuery操作DOM元素时,经常会遇到需要判断元素是否具有某个特定属性的情况。这种情况下,我们可以借助jQuery提供的方法来轻松实现这一功能。下面将介绍两种常用的方法来判断一个jQuery元素是否具有特定属性,并附上具体的代码示例。方法一:使用attr()方法和typeof操作符//判断元素是否具有特定属
