js走马灯怎么写,js跑马灯效果展示

本文目录一览:

一行文字跑马灯怎样用Jquery或js做?

使用方法:

使用该跑马灯特效之前要先引入jQuery和marquee.js文件。

script src=”jquery-1.11.2.min.js”/script script src=”marquee.js”/script

HTML结构:

跑马灯中的文字使用无序列表来制作,外面使用一个div作为包裹容器。

123456789101112    div class=”container”  div class=”marquee-sibling” Breaking News /div  div class=”marquee”    ul class=”marquee-content-items”      liItem 1/li      liItem 2/li      liItem 3/li      liItem 4/li      liItem 5/li    /ul  /div/div  

CSS样式:

下面是该跑马灯特效的一些基本样式。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354    .container {  width: 100%;  background: #4FC2E5;  float: left;  display: inline-block;  overflow: hidden;  box-sizing: border-box;  height: 45px;  position: relative;  cursor: pointer;}  .marquee-sibling {  padding: 0;  background: #3BB0D6;  width: 20%;  height: 45px;  line-height: 42px;  font-size: 12px;  font-weight: normal;  color: #ffffff;  text-align: center;  float: left;  left: 0;  z-index: 2000;}  .marquee,*[class^=”marquee”] {  display: inline-block;  white-space: nowrap;  position: absolute;}  .marquee { margin-left: 25%; }  .marquee-content-items {  display: inline-block;  padding: 5px;  margin: 0;  height: 45px;  position: relative;}  .marquee-content-items li {  display: inline-block;  line-height: 35px;  color: #fff;}  .marquee-content-items li:after {  content: “|”;  margin: 0 1em;}  

初始化插件:

123    $(function (){  createMarquee();});  

在页面加载完毕之后,可以通过下面的方法来初始化该跑马灯插件。

配置参数:

下面是该跑马灯特效的可用配置参数。

12345678910111213141516171819202122232425262728    $(function (){    createMarquee({          // controls the speed at which the marquee moves    duration:30000,       // right margin between consecutive marquees    padding:20,       // class of the actual div or span that will be used to create the marquee –     // multiple marquee items may be created using this item’s content.     // This item will be removed from the dom    marquee_class:’.example-marquee’,       // the container div in which the marquee content will animate.     container_class: ‘.example-container’,       // a sibling item to the marqueed item  that affects –     // the end point position and available space inside the container.     sibling_class: ‘.example-sibling’,       // Boolean to indicate whether pause on hover should is required.     hover: false    });  });  

javascript 怎样写了,我想在DM2004中写跑马灯(要求是跑动过程中没有后面的白的空白,)

说一下思路,

marquee scrollamount=”2″ width=”100%” onmouseover=”stop()” onmouseout=”start()”流风,飘然的风 作品/marquee

这段跑马灯从右往左滚动,在左边消失后再次循环。

楼主要的效果是右边内容一出完就开始循环而不是等到在左边消失右边的才出来吧?

从右到左循环的效果用marquee标签就可以轻松实现了,那么javascript控制的就是在右边内容跑后马上进行第二次循环,这里就需要判断什么时候右边的内容跑完?和如何让他进行第二次循环?

解决了这两个问题就很容易写代码了。

用js 实现走马灯效果,横向的怎么实现?纵向的又是怎么实现的?

!DOCTYPE html PUBLIC “-//W3C//Dtd XHTML 1.0 Transitional//EN” “”

html xmlns=””

head

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ /

title无缝滚动/title

style type=”text/css”

img{

border:0;

height:100px; width:150px;

}

td img{

margin:0 10px;

}

/style

/head

body

!– 纵向向无缝滚动–

div id=”demo” style=”overflow:hidden;height:350px;width:200px”

div id=”demo1″

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_01.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_02.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_03.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_04.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_05.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_06.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_07.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_08.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_10.jpg”/ap

a href=”#” target=”_blank”img src=”jsfile/imagesa32/gundong_11.jpg”/ap

/div

div id=”demo2″

/div

/div

script

var speed=40;

var demo2=document.getElementById(“demo2”);

var demo1=document.getElementById(“demo1”);

var demo=document.getElementById(“demo”);

demo2.innerHTML=demo1.innerHTML

function Marquee(){

if(demo2.offsetTop-demo.scrollTop=0)

demo.scrollTop-=demo1.offsetHeight;

else{

demo.scrollTop++;

}

}

var MyMar=setInterval(Marquee,speed);

demo.onmouseover=function() {clearInterval(MyMar)}

demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}

/script

!– 横向无缝滚动–

div style=”margin-top:20px;”

div id=”scroll_div” style=”overflow: hidden; WIDTH: 778px;” align=center

table border=”0″ cellpadding=”0″ cellspacing=”0″

tr

td id=”scroll_begin”

a href=”#”img src=”jsfile/imagesa32/gundong_11.jpg” border=0/aa href=”#”img src=”jsfile/imagesa32/gundong_01.jpg” border=0/aa href=”#”img src=”jsfile/imagesa32/gundong_02.jpg” border=0/aa href=”#”img src=”jsfile/imagesa32/gundong_03.jpg” border=0/aa href=”#”img src=”jsfile/imagesa32/gundong_04.jpg” border=0/aa href=”#”img src=”jsfile/imagesa32/gundong_05.jpg” border=0/aa href=”#”img src=”jsfile/imagesa32/gundong_06.jpg” border=0/aa href=”#”img src=”jsfile/imagesa32/gundong_07.jpg” border=0/a/td

td id=”scroll_end”/td

/tr

/table

/div/div

script

var speed1=40

var scroll_end = document.getElementById(“scroll_end”);

var scroll_div = document.getElementById(“scroll_div”);

scroll_end.innerHTML=scroll_begin.innerHTML

function Marquee1(){

if(scroll_end.offsetWidth-scroll_div.scrollLeft=0)

scroll_div.scrollLeft-=scroll_begin.offsetWidth

else{

scroll_div.scrollLeft++

}

}

var MyMar1=setInterval(Marquee1,speed1)

scroll_div.onmouseover=function() {clearInterval(MyMar1)}

scroll_div.onmouseout=function() {MyMar1=setInterval(Marquee1,speed1)}

/script

/body

/html

求Jquery或js一行文字跑马灯代码

这个完全是我本人自己真实项目当中的代码

其实不用js 用css3就能完成

代码如下

标签:{

background: -webkit-gradient(linear,left top,right top,color-stop(0, #3CAF5A),color-stop(0.3, #3CAF5A),color-stop(0.5, white),color-stop(0.7, #3CAF5A),color-stop(1, #3CAF5A));

background-clip: text; //文字背景区域

-webkit-background-clip: text;

-webkit-text-fill-color: transparent;

text-fill-color: transparent;

-webkit-animation: slidetounlock 2s linear infinite; //动画执行的参数 第一是 动画执行的名字   第二是所需时间  第三是执行动画的快慢infinite是均速 第四个参数是循环

animation: slidetounlock 2s linear infinite;

}  

为了兼容建议把写全 百分比是指动画执行到多少以后执行里面的动画

@keyframes slidetounlock{

0% {

background-position: -2rem 0;

}

80% {

background-position: 1rem 0;

}

100% {

background-position: 2rem 0;

}

}

@-webkit-keyframes slidetounlock{

0% {

background-position: -2rem 0;

}

80% {

background-position: 1rem 0;

}

100% {

background-position: 2rem 0;

}

}

@-moz-keyframes slidetounlock{

0% {

background-position: -1.1rem 0;

}

80% {

background-position: 1rem 0;

}

100% {

background-position: 1.1rem 0;

}

}

@-ms-keyframes slidetounlock{

0% {

background-position: -1.1rem 0;

}

80% {

background-position: 1rem 0;

}

100% {

background-position: 1.1rem 0;

}

}

@-o-keyframes slidetounlock{

0% {

background-position: -1.1rem 0;

}

80% {

background-position: 1rem 0;

}

100% {

background-position: 1.1rem 0;

}

}

之后你只需要设置文字所在容器的宽度就行,用px可以代替rem;可根据自己的需求来修改

最后效果就是

白色会一直从左到右 有点像早期苹果滑动解锁的那种动画,这个可以根据实际需求来修改

js走马灯效果

!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”

html xmlns=””

head

titlejavascript无缝滚动/title

meta charset=”gb2312″/

style type=”text/css”

#marquee ,#marquee li { padding:0px; margin:0px;}

#marquee { position:relative; list-style:none; height:150px; width:210px; padding-left:5px; overflow:hidden; border:10px solid #eee; }

#marquee li { position:absolute; font-size:12px;}

#marquee a { display:block; color:#999999; text-decoration:none;}

/style

script type=”text/javascript”

var Marquee = function(id){

try{document.execCommand(“BackgroundImageCache”, false, true);}catch(e){};

var container = document.getElementById(id),

slide = container.getElementsByTagName(“li”)[0],

speed = arguments[1] || 80, //速度

delta = 0,//当前滚动的位置

critical = slide.offsetHeight;//临界点

slide.innerHTML += slide.innerHTML;

var rolling = function(){

delta == -critical ? delta = 0 : delta–;

slide.style.top = delta + “px”;

}

var timer = setInterval(rolling,speed)//设置定时器

container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动

container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器

}

window.onload = function(){

Marquee(“marquee”);

}

/script

/head

body

ul id=”marquee”

li

a href=”#”纤云弄巧,飞星传恨,银汉迢迢暗度。/abr /

a href=”#”金风玉露一相逢,便胜却、人间无数。/abr /

a href=”#”柔情似水,佳期如梦。忍顾鹊桥归路!/abr /

a href=”#”两情若是久长时,又岂在、朝朝暮暮。/abr /

a href=”#”千重劫,百世难,亘古匆匆,弹指间!/abr /

a href=”#”不死躯,不灭魂,震古烁今,无人敌!/abr /

a href=”#”待到阴阳逆乱时,以我魔血染青天!/abr /

/li

/ul

/body

/html

原创文章,作者:JTJLK,如若转载,请注明出处:https://www.506064.com/n/329318.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
JTJLKJTJLK
上一篇 2025-01-14 18:55
下一篇 2025-01-14 18:55

相关推荐

  • JS Proxy(array)用法介绍

    JS Proxy(array)可以说是ES6中非常重要的一个特性,它可以代理一个数组,监听数据变化并进行拦截、处理。在实际开发中,使用Proxy(array)可以方便地实现数据的监…

    编程 2025-04-29
  • 解析js base64并转成unit

    本文将从多个方面详细介绍js中如何解析base64编码并转成unit格式。 一、base64编码解析 在JavaScript中解析base64编码可以使用atob()函数,它会将b…

    编程 2025-04-29
  • Node.js使用Body-Parser处理HTTP POST请求时,特殊字符无法返回的解决方法

    本文将解决Node.js使用Body-Parser处理HTTP POST请求时,特殊字符无法返回的问题。同时,给出一些相关示例代码,以帮助读者更好的理解并处理这个问题。 一、问题解…

    编程 2025-04-29
  • t3.js:一个全能的JavaScript动态文本替换工具

    t3.js是一个非常流行的JavaScript动态文本替换工具,它是一个轻量级库,能够很容易地实现文本内容的递增、递减、替换、切换以及其他各种操作。在本文中,我们将从多个方面探讨t…

    编程 2025-04-28
  • JS图片沿着SVG路径移动实现方法

    本文将为大家详细介绍如何使用JS实现图片沿着SVG路径移动的效果,包括路径制作、路径效果、以及实现代码等内容。 一、路径制作 路径的制作,我们需要使用到SVG,SVG是可缩放矢量图…

    编程 2025-04-27
  • 如何使用JS调用Python脚本

    本文将详细介绍通过JS调用Python脚本的方法,包括使用Node.js、Python shell、child_process等三种方法,以及在Web应用中的应用。 一、使用Nod…

    编程 2025-04-27
  • 如何反混淆美团slider.js

    本文将从多个方面详细阐述如何反混淆美团slider.js。在开始之前,需要明确的是,混淆是一种保护JavaScript代码的方法,其目的是使代码难以理解和修改。因此,在进行反混淆操…

    编程 2025-04-27
  • Python要学JS吗?

    Python和JavaScript都是非常受欢迎的编程语言。然而,你可能会问,既然我已经学了Python,是不是也需要学一下JS呢?在本文中,我们将围绕这个问题进行讨论,并从多个角…

    编程 2025-04-27
  • 解决js ajax post 419问题

    对于使用ajax post请求时出现的419问题,我们需要进行以下几个方面的阐述,包括返回码的含义、可能出现的情况、解决方案等内容。 一、解析419返回码 419返回码表示用户超时…

    编程 2025-04-27
  • Three.js实现室内模型行走

    在本文中,将介绍如何使用Three.js创建室内模型,并在场景中实现行走。为了实现这一目标,需要完成以下任务: 加载室内模型及材质贴图 实现摄像机控制,支持用户自由行走 添加光源,…

    编程 2025-04-25

发表回复

登录后才能评论