Lorem ip" />

Lorem ip" />

Lorem ip"/>

Switch the background-image with using effect.

Overview

jQuery.BgSwitcher Build Status

Switch the background image with using effect.

Demo

http://rewish.github.io/jquery-bgswitcher/

Usage

<div class="box">
  <p>Lorem ipsum dolor sit amet.</p>
</div>
$(".box").bgswitcher({
  images: ["pic1.jpg", "pic2.jpg", "pic3.jpg"],
  ... Something Config ...
});

For example, if you want to disable the loop of switching:

$(".box").bgswitcher({
  images: ["pic1.jpg", "pic2.jpg", "pic3.jpg"],
  loop: false
});

Configs

Key Type Default Description
images array [] Background images
interval number 5000 Interval of switching
start boolean true Start the switch on after initialization (Calling the Methods)
loop boolean true Loop the switch
shuffle boolean false Shuffle the image order
effect string fade Effect type (Built-In effect types)
duration number 1000 Effect duration
easing string swing Effect easing

Effect Types

Built-In effect types

  • fade
  • blind
  • clip
  • slide
  • drop
  • hide (No effect)

Adding the effect type

First, define effect with using the $.BgSwitcher.defineEffect().

$.BgSwitcher.defineEffect("extraSlide", function($el) {
  $el.animate({left: $el.width()}, this.config.duration, this.config.easing);
});

Then, specify the effect name that you added.

$(".box").bgswitcher({
  images: ["pic1.jpg", "pic2.jpg", "pic3.jpg"],
  effect: "extraSlide"
});

Calling the Methods

Support the method calls like jQuery UI Widget.

$(".box").bgswitcher("method name");

You can call various methods, For example:

Name Description
start Start the switching
stop Stop the switching
toggle Toggle between start/stop
reset Return to the first switching
select Select the switching at index
next Go to the next switching
prev Go to the previous switching
destroy !!Destroy BgSwitcher!!

Example for select with button:

var $el = $(".box").bgswitcher({
  images: ["foo.jpg", "bar.jpg", "baz.jpg"]
});

$("button").on("click", function() {
  $el.bgswitcher("select", 1); // bar.jpg
});

Dependencies

Requires jQuery 1.7.x or higher.

Support browsers

  • IE7+
  • and modern browsers
  • Mobile Safari

Running the Tests

Setup the modules required for testing.

git submodule update --init --recursive

You can testing in two ways:

  • Open the test/index.html in the Web browser
  • Command Line Testing with the PhantomJS
phantomjs lib/mocha-phantomjs/lib/mocha-phantomjs.coffee test/index.html

License

The MIT License, Copyright (c) 2009-2014 @rewish.

Comments
  • background attachment & position

    background attachment & position

    Hello

    What I think the parameters are missing is the background position, which is absolute now making the background scrollable. And the background position is also always top left 0 0 which is also not always wanted.

    thanks

    opened by twentyfortysix 6
  • Chrome issue

    Chrome issue

    Thanks for your jquery! good stuff! I have a doubt... on chrome, images seem to just move right a bit just before the fade transition. So you have an idea of how to fix it?

    opened by vinibrown 4
  • Console Issue from jquery.bgswitcher.js:232

    Console Issue from jquery.bgswitcher.js:232

    Hi, I am a bit new to web design so I apologize in advance if there is a quick fix to this.

    I believe that all of my code is correct, and so far my initial image is being called in, but the transition to my additional images is not happening.

    In the console, I get this: "Uncaught TypeError: undefined is not a function"

    /**
     * Switching the background image
     */
    switching: function() {
      var started = !!this._timerID;
    
      if (started) {
        this.stop();
      }
    
      this._createSwitchableElement();
      this._prepareSwitching();
    
      this.switchHandler(this.$switchable);
    

    /* The error is marked on this line of code ^ */

      if (started) {
        this.start();
      }
    },
    

    Thanks!

    opened by sethsi2581 3
  • Background repeats and spills

    Background repeats and spills

    Hello,

    Thanks for this plugin!

    I have a problem: Sometimes when loading a page with bgswitcher the images are repeated and spill oust of the container. I've noticed that the div style property contains "repeat". Is there a possibility to make it not repeating? This happens with Safari, Chrome, FF, IE under os x and win. When reloading the page it usually does not happen. Do you have a suggestion what I could do?

    Thank you! cat

    opened by cattalk 3
  • Pre-Loading Images

    Pre-Loading Images

    I've looked through the code for bgSwitcher and saw that there is a preLoad function for the images. However, on my site there is often a jump between slides on the first load (i.e. before the images are cached) where the background goes white.

    Here's the page: http://www.thgcreative.co.uk/senzala/

    Is this related to the preLoad funciton? And if so, does this mean the preLoad function isn't working properly?

    Thanks, Russ

    opened by slaterino 3
  • shuffle config doesn't take a boolean but a String

    shuffle config doesn't take a boolean but a String

    $('body').bgswitcher({ images: ["style/img/0.jpg","style/img/1.jpg","style/img/3.jpg","style/img/4.jpg"], effect: "fade", shuffle: "false", interval: 5000 });

    opened by maxdhn 3
  • background-colorの指定

    background-colorの指定

    <div id="test"> <div class="box"> <p>Lorem ipsum dolor sit amet.</p> </div> </div>

    この時、#testにbackground-colorを指定していると .boxの背景スライドショーが表示されなくなってしまうのですが、 回避する方法はございますか。 <body>へbackground-color指定する場合は問題なく動作致します。

    opened by trickstar13 2
  • Add class (or ID) to DIV

    Add class (or ID) to DIV

    Is it possible to add a class to the DIV container? It would make it much more flexible for responsive styling.

    (ie; background-size: cover works great at larger resolution, but the results are very poor on mobile phones (cover takes into account all the content down the page, resulting in a very small pixelated portion of the background image in visible viewport)

    opened by mattrock1 1
  • actions in .box

    actions in .box

    Hi, Thanks for script, but i have small problem. How i can insert actions buttons like next, prev ... : inside div (.box) ?

    Actions not working if i insert inside box div. Please help :).

    opened by eldooka 1
  • no support of background position in IE < 10

    no support of background position in IE < 10

    those versions of IE use background-position-[x/y] background-position can't be read through ".css(...)" in _copyBackgroundStyles function so background-position is not copied when using these browsers

    opened by aurmil 1
  • Blink系ブラウザでのイージング不具合について

    Blink系ブラウザでのイージング不具合について

    Demoを拝見したのですが、Blink系のブラウザでは画像切り替え時に一瞬画像が消える不具合が出ております。

    対処法などございませんでしょうか?

    ↓ちなみにこのサイトにある古いバージョンのDemoはシームレスな切り替えができているようです。 http://www.jqueryscript.net/demo/Lightweight-jQuery-Background-Slideshow-Plugin-BgSwitcher/demo/

    ちなみにIE11ではこの問題は発生しませんでした。

    宜しくお願いいたします。

    opened by oceancrawler 1
  • get index on image which is used

    get index on image which is used

    hello, is it possible to get like the index of the image that is being used right now in the bg switcher? for example i want certain objects to stand out more when a certain background is called. this would look something along the lines of this:

    if ($(".bg_div").style.background == "url(some_image.jpg)") { $(".some_div").style.color = "white"; } else { $(".some_div").style.color = "black";

    }

    however this does not work, could you show me how this can be done?

    regards,

    laurin

    opened by laurinjahns 0
  • Using jquery-bgwitcher with jquery version 1.3.2

    Using jquery-bgwitcher with jquery version 1.3.2

    HI,

    Your plugin need Jquery version 1.10 to work, but I must use Jquery 1.3.2 in my project. How can I use your plugin with Jquery 1.3.2. Thanks for making useful plugin

    opened by ngocminhxx 0
  • The bgswitcher doesn't let me assign rounded borders to the div

    The bgswitcher doesn't let me assign rounded borders to the div

    hi all,

    basically, the div that receives the images for the switching, can't have a css style of "border-radius". Somehow that can't be added to the div. What can I do for this?

    opened by gadget00 1
  • found a couple of solutions while using jquery-bgswitcher for a site

    found a couple of solutions while using jquery-bgswitcher for a site

    I had a concrete5 site that had a div with an external api form that the client wanted a fullwidth slideshow in the background of that div. So I gave your js a try. I found in Safari and Ipad Safari the fade didn't work. So I came up with a two part work around.

    I modified your js around line 288 with /** * Setup background element */ _setupBackgroundElement: function() { this.$bg = $(document.createElement('div')); this.$bg.css({ position: 'absolute', zIndex: (parseInt(this.$el.css('zIndex'), 10) || 0) - 1, overflow: 'hidden', '-webkit-transition': 'background 3s ease-out 2s', '-moz-transition': 'background 3s ease-out 2s', '-o-transition': 'background 3s ease-out 2s', transition: 'background 3s ease-in-out 2s' });

    and then added a preloader in the js where I called jquery-bgswitcher

    $(".booking-hero").bgswitcher({ images: jArray, //images: ["pic1.jpg", "pic2.jpg", "pic3.jpg"], // Background images effect: "fade", // fade, blind, clip, slide, drop, hide interval: 8000, // Interval of switching loop: true, // Loop the switching shuffle: false, // Shuffle the order of an images duration: 800, // Effect duration easing: "swing" // Effect easing });

    function preload(jArray, index) { index = index || 0; if (jArray && jArray.length > index) { var img = new Image (); img.onload = function() { preload(jArray, index + 1); } img.src = jArray[index]; }

    /* images is an array with image metadata */ preload(images); }

    Now the transition fade is working smoothly without a black flash on Safari Mac, Safari Ipad and my android phone.

    Thanks!

    opened by shnnnhickman 0
Background image segment effect as seen on [Filippo Bello's Portfolio](http://www.filippobello.com/portfolio).

Segment Effect Background image segment effect as seen on Filippo Bello's Portfolio. Article on Codrops Demo License Integrate or build upon it for fr

Codrops 526 Nov 29, 2022
Add a water ripple effect to your background using WebGL.

jQuery Ripples Plugin By the powers of WebGL, add a layer of water to your HTML elements which will ripple by cursor interaction! Important: this plug

Pim Schreurs 976 Dec 30, 2022
Recreation of the background scale hover effect seen on the DDD Hotel website using CSS clip paths.

Background Scale Hover Effect Recreation of the background scale hover effect seen on the DDD Hotel menu using CSS clip paths. Article on Codrops Demo

Codrops 98 Dec 6, 2022
Liquideffect - Javascript Library for creating liquid effect on image and RGB effect on mouse direction.

LiquidEffect Javascript Library for creating liquid effect on image and RGB effect on mouse direction. Demo https://liquideffect.netlify.app/ Dependen

Rohail 8 May 6, 2022
A decorative website background effect where SVG shapes morph and transform on scroll.

Morphing Background Shapes A decorative website background effect where SVG shapes morph and transform on scroll. Article on Codrops Demo This demo is

Codrops 351 Dec 26, 2022
A motion hover effect for a background grid of images.

Image Grid Motion Effect A motion hover effect for a background grid of images. Article on Codrops Demo Installation Install dependencies: npm install

Codrops 118 Dec 31, 2022
fixed-background-effect

Fixed Background Effect A simple template that takes advantage of the background-attachment CSS property to create a fixed background effect. Article

CodyHouse 50 Oct 28, 2022
Pure CSS Image Hover Effect Library

imagehover.css A Scaleable & Light Image Hover CSS Library Imagehover.css is a lovingly crafted CSS library allowing you to easily implement scaleable

Ciaran Walsh 1.8k Dec 21, 2022
A sticky image effect for a slideshow inspired by ultanoir's website.

How to Create a Sticky Image Effect with Three.js A sticky image effect for a slideshow inspired by ultanoir's project showcase slideshow. Article on

Daniel Velasquez 198 Nov 18, 2022
A full image reveal effect with fancy thumbnail sliding.

Full Image Reveal Effect A full image reveal effect with fancy thumbnail sliding. Article on Codrops Demo Credits Images from Unsplash.com TweenMax by

Codrops 155 Dec 19, 2022
image/video/content slideshow engine providing high quality animation effects including Kenburns Effect and GLSL Transitions.

Diaporama Diaporama is an image/video/content slideshow engine providing high quality animation effects including Kenburns effect and GLSL Transitions

Gaëtan Renaudeau 797 Nov 26, 2022
KenBurns Image Effect for React Native Applications

react-native-kenburns-view KenBurns Image Effect for React Native. Based on Image Component Image Component. Version: 4.1.0 Tested on React Native 0.6

Nimila Hiranya Samarasinghe 58 Sep 3, 2022
A tutorial on how to create a thumbnail grid with an expanding image preview similar to the effect seen on Google Images.

Thumbnail Grid with Expanding Preview A tutorial on how to create a thumbnail grid with an expanding image preview similar to the effect seen on Googl

Codrops 353 Jan 4, 2023
A speedy motion transition effect for an image slideshow.

Motion Transition Effect A speedy motion transition effect for an image slideshow. Inspired by Ping Pong Slow Motion. Article on Codrops Demo Credits

Codrops 51 Jul 5, 2022
React particles animation background component

particles-bg React component for particles backgrounds This project refers to the source code of the Proton official website, I packaged it into a com

lindelof 561 Dec 24, 2022
A vue.js particles animation background component

particles-bg-vue A vue.js particles animation background component. Use it to make your website look cool. Check it out if you want to use it in React

lindelof 206 Dec 24, 2022
Add a retro/vintage effect to images using the HTML5 canvas element

vintageJS Add a retro/vintage effect to images using the HTML5 canvas element. Installation $ npm install vintagejs How to use vintagejs is a functio

Robert Fleischmann 829 Dec 25, 2022
The slides in this slideshow wobble as they move. The effect is based on Sergey Valiukh's Dribbble shot and was made using Snap.svg and morphing SVG paths.

Wobbly Slideshow Effect The slides in this slideshow wobble as they move. The effect is based on Sergey Valiukh's Dribbble shot and was made using Sna

Codrops 112 Jul 27, 2022