how to change background image dynamically only when radio button is selected and by pressing submit button
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
You will want to use jquery to register the eventHandler with both actions.
Something like:
Using only Javascript
Test it online: http://jsfiddle.net/OscarGarcia/t70prkda/
HTML test code:
Javascript code:
Edit 1: Using jQuery
Test it online: http://jsfiddle.net/OscarGarcia/t70prkda/1/
Edit 3: Changing background image in JS and jQuery
For simplicity my code only change background color, this one changes background image: http://jsfiddle.net/OscarGarcia/t70prkda/2/
And in pure javascript: http://jsfiddle.net/OscarGarcia/t70prkda/3/
Edit 3: Smooth background image transition
Try it online: http://jsfiddle.net/OscarGarcia/2g6rfdsf/
CSS Code:
HTML Code:
Note that I'm using an overlay (a div over the background) with opacity 0 (hidden) and I'll animate the opacity. It's not possible to animate background image changes, they will change instantly.
And javascript (jQuery version) code:
When pushing button background overlay will show or hidden smoothly because CSS code
transition: all 2s ease-in-out;
while left position changes slowly too!.Hope it helps!