Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 901321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:32:17+00:00 2026-05-15T15:32:17+00:00

I have a working script like this: jQuery(document).ready(function(){ $(‘.video-thumb img’).bind(‘mouseover’,function(){ var new = $(this).attr(‘src’).replace(/default.jpg/,’1.jpg’);

  • 0

I have a working script like this:

jQuery(document).ready(function(){

    $('.video-thumb img').bind('mouseover',function(){
        var new = $(this).attr('src').replace(/default.jpg/,'1.jpg');
        $(this).attr('src',new);
    }).bind('mouseout',function(){
        var default = $(this).attr('src').replace(/[0-9].jpg/,'default.jpg');
        $(this).attr('src',default);
    });

});

Yeah, you guessed right. It’s made to change YouTube’s thumbnail on interval. However, I have no idea, how to create the interval. It now changes the thumbnail to 1.jpg, which is another thumbnail, but it should next change the image to 2.jpg in 1 second and so on.

The whole snippet should probably be written from scratch. Advice?

Hope you understood 😀

EDIT: I changed the variable-names from finnish words, I don’t use them. Just in this example.

Martti Laine

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:32:18+00:00Added an answer on May 15, 2026 at 3:32 pm

    new and default are reserved words in javascript. You cannot use them.

    To create an interval you should use setInterval:

    setInterval(function() {
      // do something
      // ...
    }, 1000); // <- 1000ms = 1s
    

    [See it in action]

    jQuery(document).ready(function() {
    
        var timer, imgsrc, cnt = 0;
    
        $('.video-thumb img').bind('mouseover', function() {
    
          // if there is no timer
          if (!timer) {
    
            var $t = $(this);
    
            // get the image src
            imgsrc = $t.attr('src').replace('default.jpg','');
    
            // start a new timer
            timer = setInterval(function() {
    
              // periodically change the src
              $t.attr('src', imgsrc + (cnt+1) + ".jpg");
    
              // and adjust the counter
              cnt = ( cnt + 1 ) % 3; // 0, 1, 2
    
            }, 1000); // <- 1000ms = 1s
          }
        }).bind('mouseout',function() {
    
          // stop rotation
          if (timer) {
            clearInterval(timer);
            timer = null;
          }
    
          // set the default img
          $(this).attr('src', imgsrc + 'default.jpg');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some simple jQuery toggle script like this: <script type=text/javascript> $(document).ready(function() { $('#clickedit').click(function()
I have jQuery validation working pretty well using a dialog for the error messages.
I have this jQuery plugin called Easy Slider which I'm implementing on this site
I have a number of Jquery plugins being called through my Drupal Acquia Marina
So I've been working recently on a script to obfuscate client-side code for protecting
I am trying to perform input validation on a user click. However the jQuery
I'm trying to build a list of checkboxes by using jQuery.tmpl It'll list an
I have run into a bug with firefox and have searched all over and
I've been implementing the new unobtrusive javascript in my mvc 3 project (using RC1).
Basically is to click button to generate table row, then click minus button to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.