最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2016年12月12日 11:19:17   作者:fighting_liu  
這篇文章主要為大家詳細(xì)介紹了如何簡(jiǎn)單實(shí)現(xiàn)jquery焦點(diǎn)圖效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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>這是一段測(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)擊事件。

更多精彩內(nèi)容大家還可以參考《jQuery焦點(diǎn)圖特效匯總》進(jìn)行學(xué)習(xí),希望大家喜歡。

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

相關(guān)文章

  • js獲取url傳值的方法

    js獲取url傳值的方法

    這篇文章主要介紹了js獲取url傳值的方法,實(shí)例分析了字符串分割與正則分析兩種方法,并補(bǔ)充了一個(gè)基于正則匹配實(shí)現(xiàn)的js獲取url的get傳值函數(shù),需要的朋友可以參考下
    2015-12-12
  • 基于JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)單的事件觸發(fā)器

    基于JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)單的事件觸發(fā)器

    這篇文章主要為大家詳細(xì)介紹了如何使用JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)單的事件觸發(fā)器,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • p5.js入門教程之小球動(dòng)畫示例代碼

    p5.js入門教程之小球動(dòng)畫示例代碼

    本篇文章主要介紹了p5.js入門教程之小球動(dòng)畫示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • 24個(gè)實(shí)用JavaScript?開(kāi)發(fā)技巧

    24個(gè)實(shí)用JavaScript?開(kāi)發(fā)技巧

    這篇文章主要給大家分享了24個(gè)實(shí)用JavaScript?的開(kāi)發(fā)技巧,文章圍繞JavaScript?的開(kāi)發(fā)技巧講解展開(kāi)全文,具有一定的參考價(jià)值,需要的朋友可以參考一下,希望對(duì)你有所幫助
    2021-12-12
  • 正則 js分轉(zhuǎn)元帶千分符號(hào)詳解

    正則 js分轉(zhuǎn)元帶千分符號(hào)詳解

    下面小編就為大家?guī)?lái)一篇正則 js分轉(zhuǎn)元帶千分符號(hào)詳解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • 微信小程序?qū)崿F(xiàn)拍照打卡功能

    微信小程序?qū)崿F(xiàn)拍照打卡功能

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)拍照打卡功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • alert出數(shù)組中的隨即值代碼

    alert出數(shù)組中的隨即值代碼

    一個(gè)alert出數(shù)組中的隨即值代碼,隨即的到min和max之間的值,經(jīng)測(cè)試,比較實(shí)用
    2014-09-09
  • vue 組件銷毀并重置的實(shí)現(xiàn)

    vue 組件銷毀并重置的實(shí)現(xiàn)

    這篇文章主要介紹了vue 組件銷毀并重置的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • JS基于clipBoard.js插件實(shí)現(xiàn)剪切、復(fù)制、粘貼

    JS基于clipBoard.js插件實(shí)現(xiàn)剪切、復(fù)制、粘貼

    這篇文章主要介紹了JS實(shí)現(xiàn)剪切、復(fù)制、粘貼——clipBoard.js 的相關(guān)資料,需要的朋友可以參考下
    2016-05-05
  • 前端的框架TDesign小程序組件庫(kù)體驗(yàn)

    前端的框架TDesign小程序組件庫(kù)體驗(yàn)

    TDesign是騰訊各業(yè)務(wù)團(tuán)隊(duì)在服務(wù)業(yè)務(wù)過(guò)程中沉淀的一套企業(yè)級(jí)設(shè)計(jì)體系,下面這篇文章主要給大家介紹了關(guān)于前端的框架TDesign小程序組件庫(kù)體驗(yàn)的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11

最新評(píng)論

灵宝市| 万源市| 阳新县| 江西省| 宾阳县| 图片| 仙居县| 东兰县| 天水市| 南投县| 于田县| 河南省| 满洲里市| 克什克腾旗| 盘锦市| 永胜县| 祁门县| 石家庄市| 芮城县| 马关县| 平利县| 连南| 于都县| 崇文区| 武城县| 肇源县| 南宁市| 手机| 兴义市| 兴义市| 富宁县| 惠州市| 石河子市| 城固县| 交口县| 平塘县| 仁布县| 张家口市| 娄烦县| 丹凤县| 左云县|