irpas技术客

Html —— 表白弹幕 特效(效果+代码)_记录、分享、总结、提升。_表白代码

irpas 7451

目录 效果代码说明

效果

鉴于图片大小,所以分开来显示的部分效果。字体颜色等都可以继续更改。

代码

表白.html

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>弹幕表白墙特效</title> <link rel="stylesheet" href="css/demo.css"/> </head> <body> <img src="images/xx.png" class="gb"/> <!--灰色的遮罩层--> <!--Tz_gray start--> <div id="Tz_gray"> <!--内容发表区--> <div class="Con"> <span class="col">颜色 <font></font> </span> <p class="txt" contenteditable="true"></p> <span class="but">清空再写</span> <ul> <li data-color="#FF8CDE">颜色 <font style="background-color:#ff8cde"></font></li> <li data-color="#C59FFF" class="xz">颜色 <font style="background-color:#c59fff"></font></li> <li data-color="#89ACFF">颜色 <font style="background-color:#89acff"></font></li> <li data-color="#92FFC1">颜色 <font style="background-color:#92ffc1"></font></li> <li data-color="#FFCC94">颜色 <font style="background-color:#ffcc94"></font></li> <li data-color="#FFFFFF">颜色 <font style="background-color:#ffffff"></font></li> </ul> </div> <div class="Text"></div> </div> <!--Tz_gray end--> <audio src="mp3/1.mp3" id="Music"></audio> <!--music end--> <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script> <script src="js/snowfall.jquery.js"></script> <script src="js/demo.js"></script> </div> </body> </html>

demo.css

/*通用初始化样式*/ * { margin: 0; padding: 0; } body, div, p, h1, h2, h3, h4, h5, h6, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, table,th,td { margin:0; padding:0; } body, button, input, select, textarea { font: 12px/24px Arial, 'Microsoft Yahei',"宋体", sans-serif; } address, cite, em, i { font-style: normal; } small { font-size: 12px; } li { list-style: none; } a { text-decoration: none; } a:hover { text-decoration: none; } legend { color: #000; } fieldset, img { border: 0; } button, input, select, textarea { font-size: 100%; line-height:normal; } table{ border-collapse: collapse; border-spacing: 0; } input[type="button"],input[type="submit"],input[type="reset"]{cursor:pointer;} iframe{ display:block; } .clearfix:after { visibility:hidden; display:block; font-size:0; content:" "; clear:both; height:0; } .clearfix { zoom:1; } /*正文样式*/ * { margin: 0px; padding: 0px; } body { background: url("../images/bg.jpg") top/100%; position: fixed } img.gb { position: fixed; /*固定*/ left: 45%; top: 0px; -webkit-animation: bd 5s ease-in-out infinite; /*动画名称 时间 运动速度 永远无限*/ } @-webkit-keyframes bd { 0% { -webkit-transform: rotate(30deg); -webkit-transform-origin: center top; } 50% { -webkit-transform: rotate(-30deg); -webkit-transform-origin: center top; } 100% { -webkit-transform: rotate(30deg); -webkit-transform-origin: center top; } } #Tz_gray { width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); position: fixed; /*固定*/ left: 0px; top: 0px; display: none; } .Con { width: 560px; height: 30px; position: fixed; left: 50%; margin-left: -280px; bottom: 130px; } .Con span.col { width: 80px; height: 30px; background: #f3f3f3; display: block; /*块级元素*/ float: left; border-radius: 4px 0px 0px 4px; font-size: 12px; line-height: 30px; text-indent: 10px; /*首行缩进*/ } .Con p.txt { width: 400px; overflow: hidden; height: 30px; background: #ffffff; float: left; line-height: 28px; } .Con span.but { width: 80px; height: 30px; background: #f4354b; display: block; float: left; font-size: 12px; color: #ffffff; text-align: center; /*水平居中*/ line-height: 30px; border-radius: 0px 4px 4px 0px;cursor: pointer; } .Con span.col font { width: 10px; height: 10px; display: block; background: #ff7182; position: absolute; /*绝对定位*/ top: 9px; left: 40px; border: 1px solid #000000 /*粗细 风格 颜色*/; } .Con ul { width: 80px; position: absolute; bottom: 28px; left: 0px; display: none; } .Con ul li { list-style-type: none; /*去掉圆点*/ width: 80px; height: 30px; font-size: 12px; line-height: 30px; text-indent: 10px; background: #f3f3f3; position: relative; } .Con ul li font { width: 10px; height: 10px; border: 1px solid #000000; display: block; position: absolute; top: 10px; left: 40px; } #Tz_gray .Text { width: 600px; height: 500px; margin: 100px auto; /*水平居中*/ color: #ffa9b7; font-size: 20px; line-height: 40px; text-align: center; } .snowfall-flakes { /*.class类选择器*/ position: relative; width: 20px !important; height: 18px !important; } .snowfall-flakes:before, .snowfall-flakes:after { content: ""; /*不管有没有内容都必须写这句*/ width: 10px; height: 16px; position: absolute; background: #ff615f; display: block; /*块级元素*/ border-radius: 10px 10px 0 0; /*圆角:左上 右上 右下 左下*/ transform: rotate(-45deg); /*css3变换:旋转*/ left: 10px; /*方位值:距离参考物左端的距离*/ top: 0px; /*距离参考物上端的距离*/ } .snowfall-flakes:before { transform: rotate(45deg); left: 14px; }

demo.js

var timer = null; emp(); function emp() { timer = setInterval(function () { auto(); },800) } $("img.gb").click(function () { $("#Tz_gray").show(); //显示 $("#Music").get(0).play(); }); //点击颜色时,显示和隐藏 $("span.col").click(function () { $(".Con ul").toggle("slow"); }); //点击颜色时,更换颜色 $(".Con ul li").click(function () { var col = $(this).data("color"); $("span.col font").css("background-color", col); $(this).addClass("xz").siblings().removeClass("xz"); //指定的加上 class="xz" 其它的移除 $(".Con ul").toggle("slow"); //隐藏 }); //当我们抬起键盘时 var arr = []; $('p.txt').blur(function () { emp(); }) $("p.txt").keyup(function (e) { clearInterval(timer); var col = $(".Con ul li.xz").data("color"); var txt = "<span style='color:" + col + "'>" + $(this).text() + "</span>"; //获取输入框内容 $(".Text").html(arr.join("").toString() + txt); //保证输入的内容同步 //判断有没有按回车键 //keyCode 的值为 13时,说明是回车键 if (e.keyCode == 13) { //清空输入框内容 $("p.txt").empty(); //清空 arr.push("<P>" + txt + "</p>"); var html = ""; for (var i = 0; i < arr.length; i++) { html += arr[i]; } $(".Text").html(html); } $('.but').click(function () { auto(); }) function auto(){ $(".Text span").animate({ opacity: 0.1 }, 500, function () { $('.Text').find('span').empty() $('.Text').find('p').remove(); }) $("p.txt").empty(); } }); $(document).snowfall({ flakeCount: 50 }) 说明

部分JS资源为额外引入的,下载即可,另外,这个特效文件我也已经上传到“资源”中了,大家可以前去下载呦!


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #表白代码 #字体颜色等都可以继续更改