国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > JS > 正文

簡(jiǎn)單實(shí)現(xiàn)jquery焦點(diǎn)圖

2024-05-06 16:33:35
字體:
供稿:網(wǎng)友

本文實(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" <ul>  <li><a href="images/1.jpg"  <li><a href="images/2.jpg"  <li><a href="images/3.jpg"  <li><a href="images/4.jpg" </ul> <p>這是一段測(cè)試文字</p> <script src="js/jquery-3.0.0.js"></script> <script type="text/javascript">      //方法一:超級(jí)簡(jiǎn)單易懂的方法  /*$("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();  })*/            //方法二:簡(jiǎn)化了方法一重復(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è)簡(jiǎn)單地焦點(diǎn)圖事例,思路:圖片路徑寫在a標(biāo)簽的href屬性里,點(diǎn)擊a得到$(this).attr("href");并把這個(gè)值給img的src。用簡(jiǎn)單地jQuery寫一個(gè)點(diǎn)擊事件。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JavaScript/Ajax教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 囊谦县| 涞水县| 北碚区| 兴义市| 临武县| 隆回县| 拜泉县| 天柱县| 行唐县| 晋城| 若羌县| 桑日县| 合川市| 大余县| 辉南县| 三原县| 凤城市| 布尔津县| 鹿泉市| 江永县| 安龙县| 英吉沙县| 无锡市| 杭州市| 密山市| 图们市| 视频| 石狮市| 兴山县| 成都市| 景泰县| 化德县| 巨鹿县| 新津县| 宝鸡市| 宁南县| 晴隆县| 平陆县| 永定县| 开平市| 蓬安县|