ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
ok im trying to learn javascript. so i choose to start out making a image slideshow banner that auto scrolls on load no special buttons. so since i had no idea were to start i found code that was free to use commercial and non commercial and ill be able to change it. heres that code:
Code:
var SLIDETIMER = 3;
var SLIDESPEED = 3;
var SCROLLTIMER = 3;
var SCROLLSPEED = 3;
var STARTINGOPACITY = 40;
// handles section to section scrolling of the content //
function slideContent(id,prefix,timer) {
var div = document.getElementById(id);
var slider = div.parentNode;
clearInterval(slider.timer);
slider.section = parseInt(id.replace(/\D/g,''));
slider.target = div.offsetTop;
slider.style.top = slider.style.top || '0px';
slider.current = slider.style.top.replace('px','');
slider.direction = (Math.abs(slider.current) > slider.target) ? 1 : -1;
slider.style.opacity = STARTINGOPACITY * .01;
slider.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
slider.timer = setInterval( function() { slideAnimate(slider,prefix,timer) }, SLIDETIMER);
}
function slideAnimate(slider,prefix,timer) {
var curr = Math.abs(slider.current);
var tar = Math.abs(slider.target);
var dir = slider.direction;
if((tar - curr <= SLIDESPEED && dir == -1) || (curr - tar <= SLIDESPEED && dir == 1)) {
slider.style.top = (slider.target * -1) + 'px';
slider.style.opacity = 1;
slider.style.filter = 'alpha(opacity=100)';
clearInterval(slider.timer);
if(slider.autoscroll) {
setTimeout( function() { autoScroll(slider.id,prefix,timer) }, timer * 1000);
}
} else {
var pos = (dir == 1) ? parseInt(slider.current) + SLIDESPEED : slider.current - SLIDESPEED;
slider.current = pos;
slider.style.top = pos + 'px';
}
}
// handles manual scrolling of the content //
function scrollContent(id,dir) {
var div = document.getElementById(id);
clearInterval(div.timer);
var sections = div.getElementsByTagName('div');
var length = sections.length;
var limit;
if(dir == -1) {
limit = 0;
} else {
if(length > 1) {
limit = sections[length-1].offsetTop;
} else {
limit = sections[length-1].offsetHeight - div.parentNode.offsetHeight + 20;
}
}
div.style.opacity = STARTINGOPACITY * .01;
div.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
div.timer = setInterval( function() { scrollAnimate(div,dir,limit) }, SCROLLTIMER);
}
function scrollAnimate(div,dir,limit) {
div.style.top = div.style.top || '0px';
var top = div.style.top.replace('px','');
if(dir == 1) {
if(limit - Math.abs(top) <= SCROLLSPEED) {
cancelScroll(div.id);
div.style.top = '-' + limit + 'px';
} else {
div.style.top = top - SCROLLSPEED + 'px';
}
} else {
if(Math.abs(top) - limit <= SCROLLSPEED) {
cancelScroll(div.id);
div.style.top = limit + 'px';
} else {
div.style.top = parseInt(top) + SCROLLSPEED + 'px';
}
}
}
// cancel the scrolling on mouseout //
function cancelScroll(id) {
var div = document.getElementById(id);
div.style.opacity = 1;
div.style.filter = 'alpha(opacity=100)';
clearTimeout(div.timer);
}
// initiate auto scrolling //
function autoScroll(id,prefix,timer,restart) {
var div = document.getElementById(id);
div.autoscroll = (!div.autoscroll && !restart) ? false : true;
if(div.autoscroll) {
var sections = div.getElementsByTagName('div');
var length = sections.length;
div.section = (div.section && div.section < length) ? div.section + 1 : 1;
slideContent(prefix + '-' + div.section,prefix,timer);
}
}
// cancel automatic scrolling //
function cancelAutoScroll(id) {
var div = document.getElementById(id);
div.autoscroll = false;
}
now my question is how would i manage to change the direction of the slide? the code itself is supposed to do multiple functions; for a image slide show, news ticker, and text scroll. so to me its a little confusing at the moment its sliding vertically i would like it to slide horizontally.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
You should look into the function slideContent. Both the direction are set (slider.direction) and the postion of the object (slider.style.top). Change the direction by giving slider.direction a different value, and I think you can set the horizontal position by using slider.style.left instead op slider.style.top, but you should check the properties of the parentNode object.
Furthermore, this is one of the best web sites I know for studying web programming: http://www.w3schools.com/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.