Image Slider JavaScript issues

General Tech Learning Aids/Tools 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

So essentially the image sliders on my Portfolio all work fine on my local files (on my desktop). Though as soon as I upload it to my live site it decides to completely not work after my first portfolio tile (the only one that works).

The current JavaScript isn't pretty and pretty repetitive and I think that's what the issue is. I've just copy and pasted the JavaScript for each slider in one .js file with different id's to correspond with the different id's of the slider i.e. #slider1, #slider2 etc

What I want to know is there a way to have all ID's for my sliders in my portfolio's to be put into one JavaScript script rather than several repeated with different element names? Right now it's just unnecessary repetition.

If you don't think that's the reason why it isn't working on live could you please point me in the right direction as to what else it could possibly be? Much appreciated!

Live site: www.hghazni.com

 

// portfolio slider
jQuery(document).ready(function ($) {

  $('#checkbox').change(function(){
    setInterval(function () {
        moveRight();
    }, 3000);
  });

	var slideCount = $('#slider ul li').length;
	var slideWidth = $('#slider ul li').width();
	var slideHeight = $('#slider ul li').height();
	var sliderUlWidth = slideCount * slideWidth;

	$('#slider').css({ width: slideWidth, height: slideHeight });

	$('#slider ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });

    $('#slider ul li:last-child').prependTo('#slider ul');

    function moveLeft() {
        $('#slider ul').animate({
            left: + slideWidth
        }, 200, function () {
            $('#slider ul li:last-child').prependTo('#slider ul');
            $('#slider ul').css('left', '');
        });
    };

    function moveRight() {
        $('#slider ul').animate({
            left: - slideWidth
        }, 200, function () {
            $('#slider ul li:first-child').appendTo('#slider ul');
            $('#slider ul').css('left', '');
        });
    };

    $('a.control_prev').click(function () {
        moveLeft();
    });

    $('a.control_next').click(function () {
        moveRight();
    });

});

// portfolio slider 2
jQuery(document).ready(function ($) {

  $
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

I figured it out, I had the jQuery link at the top in the section. Put it at the bottom and it was working fine. I have no idea how that happened! It's always the little things :)


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community