search
HomeWeb Front-endHTML Tutorial[Transfer] div css image scrolling effect_html/css_WEB-ITnose

想必大家都注意到的不循环滚动,所以出现了很多替代脚本,或iframe或JS输出,不管怎么做,都略显麻烦。下面说一下这个相对简单的实现思路:一个设定宽度并且隐藏超出它宽度的内容的容器demo,里面放demo1和demo2,demo1是滚动内容,demo2为demo1的直接克隆,通过不断改变demo1的scrollTop或者scrollLeft达到滚动的目的,当滚动至demo1与demo2的交界处时直接跳回初始位置,因为demo1与demo2一样,所以分不出跳动的瞬间,从而达到“无缝”滚动的目的。

在原作者的基础上做了一定修改,主要还是在样式上面,将表格更换为标签。

先了解一下对象的几个的属性:

innerHTML:设置或获取位于对象起始和结束标签内的 HTML

scrollHeight: 获取对象的滚动高度。

scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离

scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离

scrollWidth:获取对象的滚动宽度

offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度

offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置

offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置

offsetWidth:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的宽度

图片上无缝滚动



向上滚动



[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose



<script> <br /> <!-- <br /> var speed=10; //数字越大速度越慢 <br /> var tab=document.getElementById("demo"); <br /> var tab1=document.getElementById("demo1"); <br /> var tab2=document.getElementById("demo2"); <br /> tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo2 <br /> function Marquee(){ <br /> if(tab2.offsetTop-tab.scrollTop<=0)//当滚动至demo1与demo2交界时 <br /> tab.scrollTop-=tab1.offsetHeight //demo跳到最顶端 <br /> else{ <br /> tab.scrollTop++ <br /> } <br /> } <br /> var MyMar=setInterval(Marquee,speed); <br /> tab. {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的 <br /> tab. {MyMar=setInterval(Marquee,speed)};//鼠标移开时重设定时器 <br /> --> <br /> </script>
图片下无缝滚动



向下滚动



[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose



<script> <br /> <!-- <br /> var speed=10; //数字越大速度越慢 <br /> var tab=document.getElementById("demo"); <br /> var tab1=document.getElementById("demo1"); <br /> var tab2=document.getElementById("demo2"); <br /> tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo2 <br /> tab.scrollTop=tab.scrollHeight <br /> function Marquee(){ <br /> if(tab1.offsetTop-tab.scrollTop>=0)//当滚动至demo1与demo2交界时 <br /> tab.scrollTop+=tab2.offsetHeight //demo跳到最顶端 <br /> else{ <br /> tab.scrollTop-- <br /> } <br /> } <br /> var MyMar=setInterval(Marquee,speed); <br /> tab. {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的 <br /> tab. {MyMar=setInterval(Marquee,speed)};//鼠标移开时重设定时器 <br /> --> <br /> </script>
图片左无缝滚动



向左滚动




[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose




<script> <br /> <!-- <br /> var speed=10; //数字越大速度越慢 <br /> var tab=document.getElementById("demo"); <br /> var tab1=document.getElementById("demo1"); <br /> var tab2=document.getElementById("demo2"); <br /> tab2.innerHTML=tab1.innerHTML; <br /> function Marquee(){ <br /> if(tab2.offsetWidth-tab.scrollLeft<=0) <br /> tab.scrollLeft-=tab1.offsetWidth <br /> else{ <br /> tab.scrollLeft ; <br /> } <br /> } <br /> var MyMar=setInterval(Marquee,speed); <br /> tab. {clearInterval(MyMar)}; <br /> tab. {MyMar=setInterval(Marquee,speed)}; <br /> --> <br /> </script>
图片右无缝滚动



向右滚动




[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose
[Transfer] div css image scrolling effect_html/css_WEB-ITnose




<script> <br /> <!-- <br /> var speed=10; //数字越大速度越慢 <br /> var tab=document.getElementById("demo"); <br /> var tab1=document.getElementById("demo1"); <br /> var tab2=document.getElementById("demo2"); <br /> tab2.innerHTML=tab1.innerHTML; <br /> function Marquee(){ <br /> if(tab.scrollLeft<=0) <br /> tab.scrollLeft =tab2.offsetWidth <br /> else{ <br /> tab.scrollLeft-- <br /> } <br /> } <br /> var MyMar=setInterval(Marquee,speed); <br /> tab. {clearInterval(MyMar)}; <br /> tab. {MyMar=setInterval(Marquee,speed)}; <br /> --> <br /> </script>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the root tag in an HTML document?What is the root tag in an HTML document?Apr 29, 2025 am 12:10 AM

TheroottaginanHTMLdocumentis.Itservesasthetop-levelelementthatencapsulatesallothercontent,ensuringproperdocumentstructureandbrowserparsing.

Are the HTML tags and elements the same thing?Are the HTML tags and elements the same thing?Apr 28, 2025 pm 05:44 PM

The article explains that HTML tags are syntax markers used to define elements, while elements are complete units including tags and content. They work together to structure webpages.Character count: 159

What is the significance of <head> and <body> tag in HTML?What is the significance of <head> and <body> tag in HTML?Apr 28, 2025 pm 05:43 PM

The article discusses the roles of <head> and <body> tags in HTML, their impact on user experience, and SEO implications. Proper structuring enhances website functionality and search engine optimization.

What is the difference between <strong>, <b> tags and <em>, <i> tags?What is the difference between <strong>, <b> tags and <em>, <i> tags?Apr 28, 2025 pm 05:42 PM

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

Please explain how to indicate the character set being used by a document in HTML?Please explain how to indicate the character set being used by a document in HTML?Apr 28, 2025 pm 05:41 PM

Article discusses specifying character encoding in HTML, focusing on UTF-8. Main issue: ensuring correct display of text, preventing garbled characters, and enhancing SEO and accessibility.

What are the various formatting tags in HTML?What are the various formatting tags in HTML?Apr 28, 2025 pm 05:39 PM

The article discusses various HTML formatting tags used for structuring and styling web content, emphasizing their effects on text appearance and the importance of semantic tags for accessibility and SEO.

What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?What is the difference between the 'id' attribute and the 'class' attribute of HTML elements?Apr 28, 2025 pm 05:39 PM

The article discusses the differences between HTML's 'id' and 'class' attributes, focusing on their uniqueness, purpose, CSS syntax, and specificity. It explains how their use impacts webpage styling and functionality, and provides best practices for

What is the 'class' attribute in HTML?What is the 'class' attribute in HTML?Apr 28, 2025 pm 05:37 PM

The article explains the HTML 'class' attribute's role in grouping elements for styling and JavaScript manipulation, contrasting it with the unique 'id' attribute.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),