溫馨提示×

溫馨提示×

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

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

Js實現(xiàn)一鍵分享效果--懸浮框狀態(tài)

發(fā)布時間:2020-06-12 18:38:26 來源:網(wǎng)絡(luò) 閱讀:1074 作者:蝸牛oscersong 欄目:開發(fā)技術(shù)

一.html框架

/*整個分享區(qū)域*/
   <div id="share">
        /*分享區(qū)域的頂端文字描述*/
             <h4><img src="../img/chaohao.png">分享到...</h4>
        /*分享區(qū)域的的具體分享網(wǎng)站鏈接*/
             <ul>
                   <li><a href="#">一鍵分享</a></li>
                    ...
            </ul>
      /*分享區(qū)域的底端信息描述*/
               <div><a href="#">oscer分享</a></div>
      /*分享區(qū)域的懸浮狀態(tài)框,此設(shè)計中是引入一張分享懸浮框的圖片,根據(jù)定位放置到合適的位置*/
             <div id='shareTag'></div>
</div>

二.Js實現(xiàn)

           其實也很簡單,就是使用position控制進行隱藏,以及出現(xiàn),并加上動態(tài)效果,就可以完成。

window.onload = function(){

       var shareArea = document.getElementById('share');
       var exit = document.getElementsByClassName('close');
       var more = document.getElementById('more');
       var moreArea  = document.getElementById('moreArea');

       //鼠標(biāo)移入分享區(qū)域,分享區(qū)域內(nèi)容呈現(xiàn)
           shareArea.addEventListener("mouseover",function(){      

       	       shareArea.style.top = '0';
       	       shareArea.style.left = '0';   
            //添加一個動畫效果
       	       shareArea.className = 'animate';    
       	 
           },false);

        //鼠標(biāo)移出分享區(qū)域,分享區(qū)域內(nèi)容消失
           shareArea.addEventListener("mouseout",function(){       
 
       	     shareArea.style.top = '0';
       	     shareArea.style.left = '-280px';      
       	     shareArea.className = 'animate';     
       	 
            },false);

       //點擊差號分享內(nèi)容區(qū)域整個消失
          exit[0].addEventListener("click",function(){       
       	    shareArea.style.display = 'none';
       	 
          },false);

      //點擊更多選項彈出所有的分享內(nèi)容
          more.addEventListener("click",function(){
          	     shareArea.style.display = 'none';     	 
                 moreArea.style.display = 'block';
          },false);

          exit[1].addEventListener("click",function(){      
       	    moreArea.style.display = 'none';
       	 
          },false);
        
	}


三.效果圖

 Js實現(xiàn)一鍵分享效果--懸浮框狀態(tài)

鼠標(biāo)移動到這個圖片上,整個分享區(qū)域緩緩從左邊出來,如下圖:

 Js實現(xiàn)一鍵分享效果--懸浮框狀態(tài)

鼠標(biāo)移除這個區(qū)域,整個區(qū)域又緩緩從左邊消失,回到最初狀態(tài),當(dāng)點擊上面的差號時,整個分享區(qū)域全部從頁面中消失。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(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