>  기사  >  웹 프론트엔드  >  jQuery로 구현한 탄막 효과의 자세한 예

jQuery로 구현한 탄막 효과의 자세한 예

小云云
小云云원래의
2017-12-29 10:31:501473검색

Barrage는 매우 재미있는 경험입니다. 이 글에서는 jQuery로 구현한 사격 효과를 주로 소개합니다. 입력 텍스트와 스타일의 그라데이션을 제어하기 위해 jQuery를 결합하여 사격 효과를 분석합니다.

동영상을 볼 때 항상 약간의 공세가 있을 것입니다. 매우 고급스러워 보이는 이 특수 효과는 실제로 달성하기 어렵지 않습니다.

전체 코드는 아래와 같습니다.

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>www.php.cn弹幕</title> 
<style type="text/css"> 
  html,body{ 
    background:#efefef; 
    height:100%; 
  } 
  .danmu{ 
    width: 100px; 
    height:30px; 
    line-height: 28px; 
    background: green; 
    border-radius: 5px; 
    border:1px solid #fff; 
    color: #fff; 
    outline: none; 
  } 
  p.mask{ 
    position:fixed; 
    width:100%; 
    height:100%; 
    background:rgba(0,0,0,0.8); 
    opacity:0.5; 
    top:0px; 
    left:0px; 
  } 
  p.bottom{ 
    width:100%; 
    height:77px; 
    background:linear-gradient(#ccc,#4a4a4a); 
    position:fixed; 
    bottom:0px; 
    left:0px; 
    text-align:center; 
    line-height:77px; 
  } 
  p.bottom input.content{ 
    width:50%; 
    min-width: 200px; 
    height:37px; 
    border:none; 
    border-radius:10px 0px 0px 10px; 
    font-size:16px; 
    padding:0 10px; 
    outline:none; 
  } 
  p.bottom a.send{ 
    background-color:green; 
    color:#fff; 
    display:inline-block; 
    width:100px; 
    height:38px; 
    line-height:37px; 
    text-align:center; 
    position:relative; 
    left:-10px; 
    top:2px; 
    border-radius:0px 10px 10px 0px; 
    text-decoration:none; 
    font-family:&#39;Microsoft Yahei&#39;; 
  } 
  p.mask a.button{ 
    width:30px; 
    height:30px; 
    border-radius:50%; 
    background-color:green; 
    color:#fff; 
    position:fixed; 
    top:20px; 
    right:20px; 
    text-align:center; 
    line-height:30px; 
    font-size:20px; 
    font-family:&#39;Microsoft Yahei&#39;; 
    border:1px solid #fff; 
    text-decoration:none; 
    cursor:pointer; 
  } 
  p.text{ 
    color:#fff; 
    position:fixed; 
    right:0px; 
    font-size:20px; 
    white-space: nowrap; 
  } 
</style> 
</head> 
<body> 
<button>弹幕技术</button> 
  <p> 
    <a href="#" rel="external nofollow" rel="external nofollow">X</a> 
  </p> 
  <!-- 底部发言框前端 --> 
  <p> 
    <input></input> 
    <a href="#" rel="external nofollow" rel="external nofollow">发表言论</a> 
  </p> 
  <script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> 
  <script> 
   $("a.send").click(function(){ 
  var val=$(".content").val(); 
  var content=$("<p>"+val+"</p>"); 
  var top=Math.random()*$(document.body).height()+40+"px"; 
  content.css("top",top); 
  $(".mask").append(content); 
  content.animate({right:$(document.body).width()+100},8000,function(){ 
  $(this).remove(); 
  }) 
  }); 
  $(&#39;.button&#39;).click(function(){ 
      $(&#39;p.mask&#39;).fadeOut(500); 
    }); 
    $(".danmu").click(function(){ 
     $(&#39;p.mask&#39;).fadeIn(500); 
  }); 
</script> 
</body> 
</html>

배워보셨나요? 서둘러서 사용해 보세요.

관련 권장 사항:

CSS3 탄막 구현의 자세한 예

HTML5 텍스트 탄막 효과

WeChat 미니 프로그램에서 탄막 코드 구현

위 내용은 jQuery로 구현한 탄막 효과의 자세한 예의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.