溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

jQuery 效果學習

發(fā)布時間:2020-06-24 15:22:38 來源:網(wǎng)絡(luò) 閱讀:394 作者:seawuhai 欄目:web開發(fā)
<script type="text/javascript">
  //隱藏第二個段落,點擊more顯示一個效果
  $(document).ready(function(){
    $('p:eq(1)').hide();
    $('span.more').click(function(){
      $('p:eq(1)').animate({height:"show", width:"show", opacity:"show"},'slow');
      $(this).hide();
    });
    
    //隱藏最后段落,點擊倒數(shù)第二段落,顯示最后一個段落隱藏倒數(shù)第二段落 移動效果
    $('p:last').css('backgroundColor','#fcf').hide();
    $('p:eq(2)').css('backgroundColor','#cff').click(function(){
      var $thisPara = $(this);
      $thisPara.next().slideDown('slow', function(){
         $thisPara.slideUp('slow');
      });
    })
    
    //按鈕向左運動
    $('div.label').click(function(){
      //計算left距離
      var paraWidth = $('div.speech p').width(); //獲取段落寬度
      var $button  = $('div.button');  //獲取對象
      var buttonWidth = $button.width(); //獲取按鈕的寬度
      var paddingRight = $button.css('paddingRight');
            var paddingLeft = $button.css('paddingLeft');
      var borderRightWidth = $button.css('borderRightWidth');
            var borderLeftWidth = $button.css('borderLeftWidth');
      var totalButtonWidth = parseInt(buttonWidth, 10) + parseInt(paddingRight, 10) + parseInt(paddingLeft, 10) + parseInt(borderRightWidth, 10) + parseInt(borderLeftWidth, 10);
      var rightSide = paraWidth - totalButtonWidth;
      $('div.button').animate({'left':rightSide, height: 20}, 'slow')
    });
    //按鈕向右運動    淡入淺出效果
    $('h3').click(function(){
      $('div.button')
      .fadeTo('slow',0.4)
      .animate({'left':650},'slow')
      .fadeTo('slow',1.0)
      .slideUp('slow');
    });
    
    //改變段落字體大小
    $('div.button').click(function(){
      //獲取對象保存變量中
      var $speech = $('div.speech');
      var currentSize = $speech.css('fontSize');//獲取樣式屬性的值
      var  num = parseFloat(currentSize,10);
      var unit = currentSize.slice(-2);
      if(this.id == 'switcher-large'){
        num *= 1.4;
      } else if (this.id == 'switcher-small') {
        num /= 1.4;
      }
      $speech.css('fontSize', num + unit);
    });
    
    
    //鼠標滑過變色 使用hover方法  
    $('h3, div.label, div.button, span.more').hover(function(){
      $(this).addClass('hover');
    }, function(){
      $(this).removeClass('hover');
    });
  });
</script>
<style type="text/css">
.hover {
  cursor: pointer;
  background: #ffc;
}
</style>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI