欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

CSS+jQuery實(shí)現(xiàn)滑動幻燈片實(shí)例詳解

系統(tǒng) 3180 0

HTML部分代碼

Start with having a wrapping container div called main_view , and two sections nested inside called image_reel and paging. The image_reel will contain the sliding images, and paging contains the paging controls. Take a look at the image below for a visual.

?

    <div class="main_view">
    <div class="window">
        <div class="image_reel">
            <a href="#"><img src="reel_1.jpg" alt="" /></a>
            <a href="#"><img src="reel_2.jpg" alt="" /></a>
            <a href="#"><img src="reel_3.jpg" alt="" /></a>
            <a href="#"><img src="reel_4.jpg" alt="" /></a>
        </div>
    </div>
    <div class="paging">
        <a href="#" rel="1">1</a>
        <a href="#" rel="2">2</a>
        <a href="#" rel="3">3</a>
        <a href="#" rel="4">4</a>
    </div>
</div>
  
?

?

css+jQuery實(shí)現(xiàn)滑動幻燈片實(shí)例教程

?

CSS部分代碼

Take a look at the comments below for an explanation of the styles.

?

        /*--Main Container--*/
    .main_view {
    	float: left;
    	position: relative;
    }
    /*--Window/Masking Styles--*/
    .window {
    	height:286px;	width: 790px;
    	overflow: hidden; /*--Hides anything outside of the set width/height--*/
    	position: relative;
    }
    .image_reel {
    	position: absolute;
    	top: 0; left: 0;
    }
    .image_reel img {float: left;}
     
    /*--Paging Styles--*/
    .paging {
    	position: absolute;
    	bottom: 40px; right: -7px;
    	width: 178px; height:47px;
    	z-index: 100; /*--Assures the paging stays on the top layer--*/
    	text-align: center;
    	line-height: 40px;
    	background: url(paging_bg2.png) no-repeat;
    	display: none; /*--Hidden by default, will be later shown with jQuery--*/
    }
    .paging a {
    	padding: 5px;
    	text-decoration: none;
    	color: #fff;
    }
    .paging a.active {
    	font-weight: bold;
    	background: #920000;
    	border: 1px solid #610000;
    	-moz-border-radius: 3px;
    	-khtml-border-radius: 3px;
    	-webkit-border-radius: 3px;
    }
    .paging a:hover {font-weight: bold;} 
  

?

?

JS部分代碼

The following script contains comments explaining which jQuery actions are being performed.
1.Setting up the Image Slider
Start by showing the paging and activating the first link. Then we will calculate and adjust the width of the image_reel according to how many slides there are.

?

        //Show the paging and activate its first link
    $(".paging").show();
    $(".paging a:first").addClass("active");
     
    //Get size of the image, how many images there are, then determin the size of the image reel.
    var imageWidth = $(".window").width();
    var imageSum = $(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;
     
    //Adjust the image reel to its new size
    $(".image_reel").css({'width' : imageReelWidth}); 
  

?

?

2.Setting up the Slider Function and Timer
We first create the function for the slide event by itself ( rotate ). Then create another function ( rotateSwitch ) that will rotate and repeat that slide event (rotate).

?

        //Paging  and Slider Function
    rotate = function(){
        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
     
        $(".paging a").removeClass('active'); //Remove all active class
        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
     
        //Slider Animation
        $(".image_reel").animate({
            left: -image_reelPosition
        }, 500 );
     
    }; 
     
    //Rotation  and Timing Event
    rotateSwitch = function(){
        play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
            $active = $('.paging a.active').next(); //Move to the next paging
            if ( $active.length === 0) { //If paging reaches the end...
                $active = $('.paging a:first'); //go back to first
            }
            rotate(); //Trigger the paging and slider function
        }, 7000); //Timer speed in milliseconds (7 seconds)
    };
     
    rotateSwitch(); //Run function on launch 
  

?

?

Take a look at this tutorial for an explanation of how the timer ( setInterval ) works.

3.Hover and Click Events
In case the user wants to view the slide for a longer period of time, we will allow the slider to stop when it is hovered. Another thing to consider is we should reset the timer each time the paging is clicked. This will prevent unexpected slide switches and allow for a smoother experience.

?

        //On Hover
    $(".image_reel a").hover(function() {
        clearInterval(play); //Stop the rotation
    }, function() {
        rotateSwitch(); //Resume rotation timer
    });	
     
    //On Click
    $(".paging a").click(function() {
        $active = $(this); //Activate the clicked paging
        //Reset Timer
        clearInterval(play); //Stop the rotation
        rotateSwitch(); // Resume rotation timer
        rotate(); //Trigger rotation immediately
        return false; //Prevent browser jump to link anchor
    }); 
  

?

?

css+jQuery實(shí)現(xiàn)滑動幻燈片實(shí)例教程

?

查看演示

?

一些網(wǎng)站實(shí)例

Below are some sites that use similar techniques, check them out for inspiration!

?

?

?

?

?

淡入淡出幻燈片效果

?

首先我們建一個DIV,里面包括5張img,其中主要css部分代碼如下:

?

        #slider1{
    	margin:20px auto;
    	height:240px;
    	width:740px;
    	position:relative;
    	}	 
    #slider1 img{
    	position: absolute; 
    	top: 0px; 
    	left: 0px;
    	display:none;
    } 
  

?

原理分析:通過間隔一定時間來改變下一張圖片的z-index,實(shí)現(xiàn)淡入淡出的幻燈片效果,具體js部分代碼如下:

?

     var now=0;
      setInterval(function (){
          pre=now===0?2:now-1;
          nxt=now===4?0:now+1;
          var div=$("#slider1").children();
          div.eq(now).fadeOut(0,function(){   
		      div.css('z-index',1);       
              div.eq(nxt).css("z-index",6).fadeIn(600);
              div.eq(pre).css("z-index",4);
              div.eq(now).css("z-index",5);
              now=nxt;
          });
      },3000);
  
?

?

滾動幻燈片效果

建立兩個DIV,ID分別為slider2跟children,slider2為父div,children為子DIV,包含5張img,父 DIV(slider2)設(shè)置為overflow:hidden。主要CSS部分如下:

?

?

     #slider2{
	overflow:hidden;
        margin:20px auto;
	height:240px;
	width:740px;
	position:relative;
	}
#children img{
      	width:740px;
	height:240px;
	margin:0;
	padding:0;
	float:left;
      }
#children{
	height:240px;
        position:relative;
        width:740px;
	}
  
?

原理分析:通過間隔一定時間,來改變圖片的絕對位置,時間滾動動畫的幻燈片代碼,具體js部分代碼如下:

?

?

        var slider=1;
    setInterval(function(){
    		slider=slider===5?0:slider;		
    		var t=-slider*240;
    		slider++;
    		$("#children").animate({top:t},600);
    },3000); 
  

?

程序演示地址 http://www.js8.in/mywork/jquery_slider/

?

?

CSS+jQuery實(shí)現(xiàn)滑動幻燈片實(shí)例詳解


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产精品香蕉 | 欧美一区二区三区免费不卡 | 妈妈的朋友酷客影响 | 亚洲午夜精品国产电影在线观看 | 亚洲精品久久久久无码AV片软件 | 亚洲综合激情另类小说区 | 在线色网站 | 成在线人免费视频一区二区三区 | www.五月婷婷| 草草线在成年免费视频网站 | 亚洲精品国产综合一线久久 | 九草在线 | 精品国产一区二区三区久久 | 日本欧美国产 | 色综合天天色综合 | 久久久久久福利 | 亚洲日韩中文字幕一区 | 欧美精品二区三区 | 那格格| 欧美日韩视频在线播放 | 日本黄色免费网站 | 天天久久狠狠色综合 | A片扒开双腿进入做视频 | 中文字幕乱码视频32 | 在线欧美日韩 | 久一久久| 日日摸夜夜添夜夜添破第一 | 超级碰碰碰频视频免费观看 | 五月天丁香久久 | 爱视频福利| 激情黄视频| 2019天天干天天操 | 日韩中文字幕 | 亚洲精品欧美一区二区三区 | 欧美污污网站 | 国产在线观看中文字幕 | 欧美在线一二三区 | 午夜精品久久久久久久星辰影院 | 免费一级特黄3大片视频 | 亚洲精选一区 | 中文字幕在线看 |