簡單實(shí)現(xiàn)jquery焦點(diǎn)圖
本文實(shí)例為大家分享了jquery焦點(diǎn)圖的實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>焦點(diǎn)圖</title> <style type="text/css"> img{position: relative;} ul{list-style: none;width: 545px;position: absolute;top: 280px;left: 170px;} li{float: left;width: 20px;line-height: 18px;border: 1px solid #ccc;background-color:#494a93;} a:hover{background-color: red;} a{display: block;width: 20px;line-height: 18px;color: white;text-decoration: none;text-align: center;font-size: 12px;font-family: arial;} p{width: 480px;text-align: center;} </style> </head> <body> <img src="images/1.jpg" alt=""> <ul> <li><a href="images/1.jpg" title="日落">1</a></li> <li><a href="images/2.jpg" title="鋼琴">2</a></li> <li><a href="images/3.jpg" title="大海">3</a></li> <li><a href="images/4.jpg" title="秋色">4</a></li> </ul> <p>這是一段測試文字</p> <script src="js/jquery-3.0.0.js"></script> <script type="text/javascript"> //方法一:超級(jí)簡單易懂的方法 /*$("ul li:nth-child(1) a").click(function(event){ $("img").attr("src","images/1.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("img").attr("src",$(this).attr("href")) $("ul li:nth-child(1)").css("background-color","red") $("ul li:nth-child(2)").css("background-color","#494a93") $("ul li:nth-child(3)").css("background-color","#494a93") $("ul li:nth-child(4)").css("background-color","#494a93") event.preventDefault(); }) $("ul li:nth-child(2) a").click(function(event){ $("img").attr("src","images/2.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("ul li:nth-child(2)").css("background-color","red") $("ul li:nth-child(1)").css("background-color","#494a93") $("ul li:nth-child(3)").css("background-color","#494a93") $("ul li:nth-child(4)").css("background-color","#494a93") event.preventDefault(); }) $("ul li:nth-child(3) a").click(function(event){ $("img").attr("src","images/3.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("ul li:nth-child(3)").css("background-color","red") $("ul li:nth-child(2)").css("background-color","#494a93") $("ul li:nth-child(1)").css("background-color","#494a93") $("ul li:nth-child(4)").css("background-color","#494a93") event.preventDefault(); }) $("ul li:nth-child(4) a").click(function(event){ $("img").attr("src","images/4.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("ul li:nth-child(4)").css("background-color","red") $("ul li:nth-child(2)").css("background-color","#494a93") $("ul li:nth-child(3)").css("background-color","#494a93") $("ul li:nth-child(1)").css("background-color","#494a93") event.preventDefault(); })*/ //方法二:簡化了方法一重復(fù)的代碼量 ,利用.parent().siblings().find("a")選擇到父級(jí)的其他兄弟元素 $("ul li a").click(function(event){ /*$("img").attr("src","images/4.jpg")*/ var imgsrc=$(this).attr("href"); $("img").attr("src",imgsrc); $(this).css({"background-color":"red","color":"yellow"}); $(this).parent().siblings().find("a").css({"background-color":"#494a93","color":"white"}); event.preventDefault(); var txt=$(this).attr("title"); console.log(txt); //在控制臺(tái)輸出 $("p").text(txt); }) /*$("ul li a").hover(function(event){ $(this).css("background-color","red"); },function(){ $(this).css("background-color","#494a93") })*/ </script> </body> </html>
以上是一個(gè)簡單地焦點(diǎn)圖事例,思路:圖片路徑寫在a標(biāo)簽的href屬性里,點(diǎn)擊a得到$(this).attr("href");并把這個(gè)值給img的src。用簡單地jQuery寫一個(gè)點(diǎn)擊事件。
更多精彩內(nèi)容大家還可以參考《jQuery焦點(diǎn)圖特效匯總》進(jìn)行學(xué)習(xí),希望大家喜歡。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jQuery實(shí)現(xiàn)金額錄入框
- jQuery 獲取select選中值及清除選中狀態(tài)
- jQuery內(nèi)存泄露解決辦法
- 淺析Jquery操作select
- jQuery中animate的幾種用法與注意事項(xiàng)
- jQuery中值得注意的trigger方法淺析
- jQuery實(shí)現(xiàn)字符串全部替換的方法
- 基于jquery實(shí)現(xiàn)的鼠標(biāo)懸停提示案例
- jquery滾動(dòng)條插件(可以自定義)
- jquery實(shí)現(xiàn)簡單的瀑布流布局
- 基于jQuery實(shí)現(xiàn)的查看全文功能【實(shí)用】
- jQuery學(xué)習(xí)筆記之入門
相關(guān)文章
基于JS實(shí)現(xiàn)視頻上傳顯示進(jìn)度條
這篇文章主要介紹了基于JS實(shí)現(xiàn)視頻上傳顯示進(jìn)度條,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05原生JS實(shí)現(xiàn)的自動(dòng)輪播圖功能詳解
這篇文章主要介紹了原生JS實(shí)現(xiàn)的自動(dòng)輪播圖功能,結(jié)合實(shí)例形式詳細(xì)分析了基于原生js實(shí)現(xiàn)輪播圖的原理、操作步驟及操作注意事項(xiàng),需要的朋友可以參考下2018-12-12javascript 像素拼圖實(shí)現(xiàn)代碼
非常不錯(cuò)的像素拼圖效果2009-04-04微信小程序引入外部icon(阿里巴巴矢量圖標(biāo))的全過程
在小程序中,有默認(rèn)的圖標(biāo)icon組件,但你會(huì)發(fā)現(xiàn)它的圖標(biāo)樣式很少,可能很多時(shí)候并不能滿足我們的需求,所以這篇文章主要給大家介紹了關(guān)于微信小程序引入外部icon(阿里巴巴矢量圖標(biāo))的相關(guān)資料,需要的朋友可以參考下2022-09-09js+canvas實(shí)現(xiàn)網(wǎng)站背景鼠標(biāo)吸附線條動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了js+canvas實(shí)現(xiàn)網(wǎng)站背景鼠標(biāo)吸附線條動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07JS表格組件神器bootstrap table詳解(強(qiáng)化版)
這篇文章主要以實(shí)例的方式為大家再次介紹了JS表格組件神器bootstrap table,bootstrap table界面采用扁平化的風(fēng)格,用戶體驗(yàn)比較好,更好兼容各種客戶端,需要了解更多bootstrap table的朋友可以參考下2016-05-05javascript 獲取網(wǎng)頁標(biāo)題代碼實(shí)例
這篇文章主要介紹了javascript 獲取網(wǎng)頁標(biāo)題代碼實(shí)例,有需要的朋友可以參考一下2014-01-01JavaScript中的函數(shù)申明、函數(shù)表達(dá)式、箭頭函數(shù)
js中的函數(shù)可以通過幾種方式創(chuàng)建,具體創(chuàng)建方法通過實(shí)例代碼給大家介紹的非常詳細(xì),文中通過例子給大家介紹了函數(shù)聲明和表達(dá)式之間的差別,感興趣的朋友跟隨小編一起看看吧2019-12-12