js實(shí)現(xiàn)七夕表白彈幕效果 jQuery實(shí)現(xiàn)彈幕技術(shù)
本文實(shí)例為大家分享了js與jQuery技術(shù)實(shí)現(xiàn)表白彈幕,供大家參考,具體內(nèi)容如下
js七夕表白彈幕效果簡(jiǎn)單版效果:
關(guān)鍵代碼:
<script> var si; function tangmu(){ clearInterval(si); var text = document.getElementById("text"); var tangmu = document.getElementById("tangmu"); var textStyle="<font id=\"textStyle\">"+text.value+"</font>"; mathHeight = Math.round(Math.random()*tangmu.offsetHeight)+"px"; var textLeft=tangmu.offsetWidth+"px"; tangmu.innerHTML=textStyle; var textStyleObj = document.getElementById("textStyle"); textStyleObj.style.left=textLeft; textStyleObj.style.top=mathHeight; var x=parseInt(textStyleObj.style.left); si = setInterval("xunhuan("+x+")",100); } function xunhuan(left){ var textStyleObj = document.getElementById("textStyle"); textStyleObj.style.left=left; var x=parseInt(textStyleObj.style.left); if(x<textStyleObj.style.width){ document.getElementById("tangmu").innerHTML=""; clearInterval(si); }else{ x-=18; } textStyleObj.style.left=x+"px"; } </script>
jQuery實(shí)現(xiàn)彈幕技術(shù):
效果:
關(guān)鍵代碼:
<script src="jquery-1.11.1.js"></script> <script> $(function () { $(".showBarrage,.s_close").click(function () { $(".barrage,.s_close").toggle("slow"); }); init_barrage(); }) //提交評(píng)論 $(".send .s_btn").click(function () { var text = $(".s_text").val(); if (text == "") { return; } var _lable = $("<div style='right:20px;top:0px;opacity:1;color:" + getRandomColor() + ";'>" + text + "</div>"); $(".mask").append(_lable.show()); init_barrage(); }) //初始化彈幕技術(shù) function init_barrage() { var _top = 0; $(".mask div").show().each(function () { var _left = $(window).width() - $(this).width();//瀏覽器最大寬度,作為定位left的值 var _height = $(window).height();//瀏覽器最大高度 _top += 75; if (_top >= (_height - 130)) { _top = 0; } $(this).css({left: _left, top: _top, color: getRandomColor()}); //定時(shí)彈出文字 var time = 10000; if ($(this).index() % 2 == 0) { time = 15000; } $(this).animate({left: "-" + _left + "px"}, time, function () { $(this).remove(); }); } ); } //獲取隨機(jī)顏色 function getRandomColor() { return '#' + (function (h) { return new Array(7 - h.length).join("0") + h })((Math.random() * 0x1000000 << 0).toString(16)) } </script>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- jquery.jsPlumb實(shí)現(xiàn)拓?fù)鋱D
- JavaScript/jQuery實(shí)現(xiàn)切換頁(yè)面效果
- JavaScript實(shí)現(xiàn)樓梯滾動(dòng)特效(jQuery實(shí)現(xiàn))
- ajax在js中和jQuery中的用法實(shí)例詳解
- JavaScript與JQuery框架基礎(chǔ)入門教程
- JS實(shí)現(xiàn)jQuery的append功能
- jQuery是用來(lái)干什么的 jquery其實(shí)就是一個(gè)js框架
- JavaScript中通用的jquery動(dòng)畫(huà)滾屏實(shí)例
相關(guān)文章
點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí)的簡(jiǎn)單js代碼(推薦)
下面小編就為大家?guī)?lái)一篇點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí)的簡(jiǎn)單js代碼(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06基于JavaScript打造一款桌面級(jí)便簽系統(tǒng)
本文將用html,css和JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)單的便簽系統(tǒng)。除非手動(dòng)清空便簽,否則便簽會(huì)一直保留,非常方便。感興趣的小伙伴可以跟隨小編一起動(dòng)手試一試2022-02-02封裝好的省市地區(qū)聯(lián)動(dòng)控件附下載
封裝好的省市地區(qū)聯(lián)動(dòng)控件附下載...2007-08-08JS實(shí)現(xiàn)為動(dòng)態(tài)添加的元素增加事件功能示例【基于事件委托】
這篇文章主要介紹了JS實(shí)現(xiàn)為動(dòng)態(tài)添加的元素增加事件功能,結(jié)合實(shí)例形式分析了javascript基于事件委托實(shí)現(xiàn)針對(duì)動(dòng)態(tài)添加的元素增加事件的相關(guān)操作技巧,需要的朋友可以參考下2018-03-03Javascript防止圖片拉伸的自適應(yīng)處理方法
這篇文章主要給大家介紹了關(guān)于利用Javascript防止圖片拉伸的自適應(yīng)處理方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12javascript字體顏色控件的開(kāi)發(fā) JS實(shí)現(xiàn)字體控制
小編給大家?guī)?lái)一個(gè)用javascript編寫(xiě)的能控制字體大小個(gè)顏色等基本信息的控件寫(xiě)法,喜歡的嘗試編寫(xiě)一下。2017-11-11js鎖屏解屏通過(guò)對(duì)$.ajax進(jìn)行封裝實(shí)現(xiàn)
js鎖屏解屏是通過(guò)對(duì)$.ajax進(jìn)行封裝實(shí)現(xiàn)的,需要的朋友可以參考下2014-07-07HTML+CSS+JS實(shí)現(xiàn)的簡(jiǎn)單應(yīng)用小案例分享
這篇文章主要為大家分享四個(gè)用HTML+CSS+JS實(shí)現(xiàn)的簡(jiǎn)單應(yīng)用小案例,有:猜數(shù)字、表白墻、切換日夜間模式和待辦事項(xiàng),需要的可以參考一下2022-02-02