熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JS仿QQ商城點擊左右滾動jquery焦點圖特效

2013-11-15 12:06:10  來源: JSP教程 

  <!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "

  <html xmlns=" <head> <meta httpequiv="ContentType" content="text/html; charset=gb" /> <style type="text/css"> body {fontsize:px; color:#; fontfamily:VerdanaArialHelveticasansserif; background:#fff;} ulli {liststyle:none; margin:px; padding:px;} img {border:;} /* 仿QQ商城點擊左右滾動jquery焦點圖特效插件 */ focus {width:px; height:px; overflow:hidden; position:relative;} focus ul {height:px; position:absolute;} focus ul li {float:left; width:px; height:px; overflow:hidden; position:relative; background:#;} focus ul li div {position:absolute; overflow:hidden;} focus btnBg {position:absolute; width:px; height:px; left:; bottom:; background:#; display:none;} focus btn {position:absolute; width:px; height:px; padding:px px px px; right:; bottom:px; textalign:right;} focus btn span {display:inlineblock; _display:inline; _zoom:; width:px; height:px; lineheight:px; textalign:center; _fontsize:; marginleft:px; cursor:pointer; background:#fff;} focus btn spanon {background:#fff;} focus preNext {width:px; height:px; position:absolute; top:px; background:url(img/spritepng) norepeat ; cursor:pointer;} focus pre {left:;} focus next {right:; backgroundposition:right top;} </style> <script type="text/javascript" src="js/jqueryminjs"></script> <script type="text/javascript" src="js/sljs"></script> <script type="text/javascript"> $(document)ready(function(){ $focus("#focus"); $focus("#focus"); }); </script> </head> <body> <h></h> <div class="focus" id="focus"> <ul> <li><a href="特效" /></a></li> <li><a href=" <li><a href="仿QQ商城點擊左右滾動jquery焦點圖特效" /></a></li> </ul> </div> <p>修改的幾個地方隱藏了半透明背景條把那個小常條滑塊讀出了這些數字 你不喜歡這樣你可以修改樣式和自己改動下jquery代碼</p> <p>調用方法很簡單$focus("#focus"); 一些參數設置可以修改js中的設置源作者已經注釋的很清楚了</p> </body> </html>

  JS

  $(function() { jQueryfocus = function(slid) { var sWidth = $(slid)width(); //獲取焦點圖的寬度(顯示面積) var len = $(slid)find("ul li")length; //獲取焦點圖個數 var index = ; var picTimer; //以下代碼添加數字按鈕和按鈕後的半透明條還有上一頁下一頁兩個按鈕 var btn = "<div class=btnBg></div><div class=btn>"; for(var i=; i < len; i++) { var ii = i+; btn += "<span>"+ii+"</span>"; } btn += "</div><div class=preNext pre></div><div class=preNext next></div>"; $(slid)append(btn); $(slid)find("divbtnBg")css("opacity");//find() 函數返回在字符串中子字符串的位置 //為小按鈕添加鼠標滑入事件以顯示相應的內容 $(slid+" divbtn span")css("opacity")mouseenter(function() { index = $(slid+" btn span")index(this); showPics(index); })eq()trigger("mouseenter"); //上一頁下一頁按鈕透明度處理 $(slid+" preNext")css("opacity")hover(function() { $(this)stop(truefalse)animate({"opacity":""}); }function() { $(this)stop(truefalse)animate({"opacity":""}); }); //上一頁按鈕 $(slid+" pre")click(function() { index = ; if(index == ) {index = len ;} showPics(index); }); //下一頁按鈕 $(slid+" next")click(function() { index += ; if(index == len) {index = ;} showPics(index); }); //本例為左右滾動即所有li元素都是在同一排向左浮動所以這裡需要計算出外圍ul元素的寬度 $(slid+" ul")css("width"sWidth * (len)); //鼠標滑上焦點圖時停止自動播放滑出時開始自動播放 $(slid)hover(function() { clearInterval(picTimer); }function() { picTimer = setInterval(function() { showPics(index); index++; if(index == len) {index = ;} }); //此代表自動播放的間隔單位毫秒 })trigger("mouseleave"); //顯示圖片函數根據接收的index值顯示相應的內容 function showPics(index) { //普通切換 var nowLeft = index*sWidth; //根據index值計算ul元素的left值 $(slid+" ul")stop(truefalse)animate({"left":nowLeft}); //通過animate()調整ul元素滾動到計算出的position $(slid+" btn span")removeClass("on")eq(index)addClass("on"); //為當前的按鈕切換到選中的效果 $(slid+" btn span")stop(truefalse)animate({"opacity":""})eq(index)stop(truefalse)animate({"opacity":""}); //為當前的按鈕切換到選中的效果 } }; });


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20292.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.