Javascript Image Slider / Posts /

How to adjust slider divmc-caption-bg left margin and width from javascript

2
How can I adjust the #slider div.mc-caption-bg left margin and width from javascript after page loads?


Jason  4 years ago   viewed: 2155    

5 Answers

1

It is specified in the js-image-slider.css file. Why not update it there?

If you have to do it through JavaScript due to a more complicated requirement, you can do it like below:

var sliderDivs = document.getElementById("slider").getElementsByTagName("div");

for(var i=0; i<sliderDivs.length; i++){

    if(sliderDivs[i].className == "mc-caption-bg")

         var captionBg = sliderDivs[i];

}

if(captionBg){

    captionBg.style.marginLeft = "-200px";

    captionBg.style.width = "300px";

}

Milo   4 years ago
1

Thanks for your reply!


That works great and like you stated can more easily be accomplished with the style sheet.  However, my problem is that while the image is centered on the page I would like to extend the caption container across the entire width of the page.  Would this be possible?

Jason   4 years ago
0
Or would it be possible to maybe trigger an external function that could handle the positioning and text as the slider rotates?


Jason   4 years ago
0

There is a callback function for each rotates. You can find it in the page http://www.menucool.com/slider/javascript-image-slider-demo4#builtinfunctions

Milo   4 years ago
-1

I'm using js to center pages according to screen size for different displays.  I would like to use the values that I calculate for left margin and width to adjust where the caption starts and ends when the page loads (like i do for the other containers).


BTW if I set static values in the style sheet the image is centered and the caption extends the width of the page but when i test on different monitor sizes the static values don't work because they are calculated for just that specific screen width.


What do you think?

Jason   4 years ago

   

Your name*
Password
(Optional. Used to modify this post afterwords)
+ =  

Ask your Own Question

  • If your question is related to the topic of this post, you can post your question to this page by clicking the "Post a reply" button at left;

  • When you want to start a new page for your question: