스크롤 텍스트 상자를 만들기 위해 다음 스 니펫을 사용하고 있습니다.
<html>
<head>
<style type="text/css">
#scroll {
position: absolute;
white-space: nowrap;
top: 0px;
left: 200px;
}
#oScroll {
margin: 0px;
padding: 0px;
position: relative;
width: 200px;
height: 20px;
overflow: hidden;
}
</style>
<script type="text/javascript">
function scroll(oid, iid) {
this.oCont = document.getElementById(oid)
this.ele = document.getElementById(iid)
this.width = this.ele.clientWidth;
this.n = this.oCont.clientWidth;
this.move = function() {
this.ele.style.left = this.n + "px"
this.n--
if (this.n < (-this.width)) {
this.n = this.oCont.clientWidth
}
}
}
var vScroll
function setup() {
vScroll = new scroll("oScroll", "scroll");
setInterval("vScroll.move()", 20)
}
onload = function() {
setup()
}
</script>
</head>
<body>
<div id="oScroll">
<div id="scroll">This is the scrolling text</div>
</div>
</body>
</html>
그러나 '스크롤링'이미지를 만들려고 <img>
합니다. 'This is the scrolling text'div 내에 태그 를 만들려고 할 때마다 페이지에 표시되지 않습니다.
나는 자바 스크립트를 처음 접했고 (완전한 초보자) 누군가이 이미지를이 효과에 추가하는 방법을 알려 주면 감사하겠습니다.
포토샵 등에서 내 자신의 gif 이미지를 만드는 것 외에는 이와 같은 것을 만드는 방법을 찾을 수 없었습니다.
편집 그러나 marqee를 사용해 보았습니다.
128px 높이의 이미지를 div에 추가하려면 포함하는 요소의 높이도 20px에서 128px로 변경해야합니다.
작동하는 코드는 다음과 같습니다.
<html>
<head>
<style type="text/css">
#scroll {
position: absolute;
white-space: nowrap;
top: 0px;
left: 200px;
}
#oScroll {
margin: 0px;
padding: 0px;
position: relative;
width: 200px;
height: 128px;
overflow: hidden;
}
</style>
<script type="text/javascript">
function scroll(oid, iid) {
this.oCont = document.getElementById(oid)
this.ele = document.getElementById(iid)
this.width = this.ele.clientWidth;
this.n = this.oCont.clientWidth;
this.move = function() {
this.ele.style.left = this.n + "px"
this.n--
if (this.n < (-this.width)) {
this.n = this.oCont.clientWidth
}
}
}
var vScroll
function setup() {
vScroll = new scroll("oScroll", "scroll");
setInterval("vScroll.move()", 20)
}
onload = function() {
setup()
}
</script>
</head>
<body>
<div id="oScroll">
<img id="scroll" src='http://i.stack.imgur.com/P8i8o.png' />
</div>
</body>
</html>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다