interactive_bg

Create an interactive moving background/object that reacts to viewer's cursor

  • 所有者: peachananr/interactive_bg
  • 平台:
  • 許可證: GNU General Public License v3.0
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

#Interactive BG (Background) by Pete R.
A jQuery plugin that will let you create an interactive moving background/object that reacts to viewer's cursor
Created by Pete R., Founder of Travelistly and BucketListly

License: Attribution-ShareAlike 4.0 International

Interactive BG (Background)

Demo

View demo

Compatibility

Modern browsers such as Chrome, Firefox, and Safari on both desktop and smartphones have been tested. Not tested on IE.

Basic Usage

To add a cool parallax like effect to your background, you will have to include the latest jQuery library (preferably version 2.0.0 or higher) together with jquery.interactive_bg.js into your document's <head>. Make sure you have a background image ready to be used.

Prepare your HTML as follows:

<body>
  ..
  <div class="bg" data-ibg-bg="bg.jpg"></div>
  ..
</body>

The data-ibg-bg attribute must reflect the location of the image you want to use as your background. For example, if your image is on the root folder and is called "background.png", change the attribute to "/background.png".

Now call the function as follows and your background will magically reacts to viewers cursor.

 $(".bg").interactive_bg({
   strength: 25,              // Movement Strength when the cursor is moved. The higher, the faster it will reacts to your cursor. The default value is 25.
   scale: 1.05,               // The scale in which the background will be zoomed when hovering. Change this to 1 to stop scaling. The default value is 1.05.
   animationSpeed: "100ms",   // The time it takes for the scale to animate. This accepts CSS3 time function such as "100ms", "2.5s", etc. The default value is "100ms".
   contain: true,             // This option will prevent the scaled object/background from spilling out of its container. Keep this true for interactive background. Set it to false if you want to make an interactive object instead of a background. The default value is true.
   wrapContent: false         // This option let you choose whether you want everything inside to reacts to your cursor, or just the background. Toggle it to true to have every elements inside reacts the same way. The default value is false
 });

Advanced Features

The problem with using options above is all your planets will look the same. To specify each of your planet's style, you can utilize the HTML markup I've provided:

Responsive Background

To make the background responsive to the windows width and height, make sure you add this snippet below the function call as follows:


  $(document).ready(function(){
    
    $(".bg").interactive_bg(); // function call
	});
  
  // change background size on window resize
  $(window).resize(function() {
	  $(".bg > .ibg-bg").css({
	    width: $(window).outerWidth(),
	    height: $(window).outerHeight()
	  })
	})

Accelerometer on Mobile

Since mouse event is not available on mobile, the plugin will automatically switch to react to the mobile's accelerometer instead without you having to do anything. Just call the function normally, and the plugin will detects and switch to the fallback automatically.

Now your background will have this interactive parallax effect like no other sites have for a minimal effort.

If you want to see more of my plugins, visit The Pete Design, or follow me on Twitter and Github.

Other Resources

  • Tutorial (Coming Soon)

主要指標

概覽
名稱與所有者peachananr/interactive_bg
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證GNU General Public License v3.0
所有者活动
創建於2014-03-30 00:23:44
推送於2020-05-08 01:17:32
最后一次提交2020-05-08 08:17:31
發布數0
用户参与
星數232
關注者數14
派生數76
提交數5
已啟用問題?
問題數10
打開的問題數9
拉請求數0
打開的拉請求數1
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?