├── img
├── 1.jpg
├── 2.jpg
├── 3.jpg
├── 4.jpg
└── 5.jpg
├── LICENSE
├── easy_background.min.js
├── README.md
├── index.html
├── CODE_OF_CONDUCT.md
└── easy_background.js
/img/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eugeniosegala/easy_background/HEAD/img/1.jpg
--------------------------------------------------------------------------------
/img/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eugeniosegala/easy_background/HEAD/img/2.jpg
--------------------------------------------------------------------------------
/img/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eugeniosegala/easy_background/HEAD/img/3.jpg
--------------------------------------------------------------------------------
/img/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eugeniosegala/easy_background/HEAD/img/4.jpg
--------------------------------------------------------------------------------
/img/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eugeniosegala/easy_background/HEAD/img/5.jpg
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Eugenio Segala
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/easy_background.min.js:
--------------------------------------------------------------------------------
1 | function easy_background(e,t){var n=document.createElement("div");n.innerHTML=" ",n.classList.add("easy_slider"),document.body.insertBefore(n,document.body.firstChild),t.slide.forEach(function(e,n){var o;e&&(document.querySelector(".easy_slider").innerHTML+=(o=e)?"":"",void 0!==t.delay[n]&&""!=typeof t.delay[n]&&0!=t.delay[n]||(t.delay[n]=3e3))}),document.querySelector(".easy_slider").style.display="none",document.querySelector(e).style.backgroundSize="cover",document.querySelector(e).style.backgroundRepeat="no-repeat",document.querySelector(e).style.backgroundPosition="center center",setTimeout(function(){void 0===t.transition_timing&&(t.transition_timing="ease-in"),void 0===t.transition_duration&&(t.transition_duration=500);var n="all "+t.transition_duration+"ms "+t.transition_timing;document.querySelector(e).style.WebkitTransition=n,document.querySelector(e).style.MozTransition=n,document.querySelector(e).style.MsTransition=n,document.querySelector(e).style.OTransition=n,document.querySelector(e).style.transition=n},100);var o=1,r=0;function i(){t.slide.forEach(function(n,i){o>1?(setTimeout(function(){document.querySelector(e).style.backgroundImage="url('"+n+"')"},r),r+=t.delay[i]):(o++,r=t.delay[i],document.querySelector(e).style.backgroundImage="url('"+n+"')")})}i(),setInterval(function(){i()},t.delay.length)}
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # easy_background
2 |
3 | An extremely lightwell, easy and clear SlideShow Background dev in Vanilla JS.
4 |
5 | This script can be used as a digital advertising spot (images pass on the screen at defined intervals).
6 |
7 | Guide:
8 |
9 | Just insert:
10 |
11 | ```
12 |
13 | ```
14 |
15 | and call easy_background:
16 |
17 | ```
18 |
19 | // FIRST CHOOSE THE CONTAINER (selector), AFTER SET THE IMAGE AND THEN THE DELAY TIME.
20 | // DEFAULT DELAY: 3s.
21 |
22 | easy_background("body",
23 |
24 | {
25 | slide: ["img/1.jpg", "img/2.jpg", "img/3.jpg", "img/4.jpg", "img/5.jpg"],
26 |
27 | delay: [2000, 2000, 2000, 2000, 2000]
28 | }
29 |
30 | );
31 | ```
32 |
33 |
34 |
35 |
36 | # MIT License
37 |
38 | Copyright (c) 2017 Eugenio Segala
39 |
40 | Permission is hereby granted, free of charge, to any person obtaining a copy
41 | of this software and associated documentation files (the "Software"), to deal
42 | in the Software without restriction, including without limitation the rights
43 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44 | copies of the Software, and to permit persons to whom the Software is
45 | furnished to do so, subject to the following conditions:
46 |
47 | The above copyright notice and this permission notice shall be included in all
48 | copies or substantial portions of the Software.
49 |
50 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56 | SOFTWARE.
57 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | easy_background
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
53 |
54 |
55 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at eugenio.segala@hotmail.it. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/easy_background.js:
--------------------------------------------------------------------------------
1 | /*!-----------------------------------------------------------------------------
2 | * easy_background
3 | * v2.0 - built 2017-10-30
4 | * Licensed under the MIT License.
5 | * http://www.testersite.it/github/easy_background/v3/
6 | * ----------------------------------------------------------------------------
7 | * Copyright (C) 2017 Eugenio Segala
8 | * --------------------------------------------------------------------------*/
9 |
10 | function easy_background(selector, sld_args) {
11 |
12 | function empty_img(x) {
13 | if (x) {
14 | return "";
15 | } else {
16 | return "";
17 | }
18 | }
19 |
20 | //use object same as arrays in php {nameofindex:variable} inside object you can use arrays [value1,val2] (variable in object can be as array
21 | //var sld_args={i:["img/555.jpg","img/44.jpg","img/33.jpg","img/22.jpg","img/11.jpg","img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg"],d:[3000,3000,3000,3000,3000] };
22 |
23 | //if delay is empty or forgotten then use this default value
24 | var def_del = 3000;
25 |
26 | var p = document.createElement("div");
27 | p.innerHTML = " ";
28 | p.classList.add("easy_slider");
29 |
30 | document.body.insertBefore(p, document.body.firstChild);
31 | //switch all values in object -- objectname.index in you case sld_args is object and i is index of array which keep images (i). We use this function for fill div with img tags
32 | //and for insert delays into empty or forgotten places in object
33 | sld_args.slide.forEach(function(v, i) {
34 | if (v) {
35 | document.querySelector(".easy_slider").innerHTML += empty_img(v);
36 | if (typeof sld_args.delay[i] == 'undefined' || typeof sld_args.delay[i] == '' || sld_args.delay[i] == 0) {
37 | sld_args.delay[i] = def_del;
38 | }
39 | }
40 |
41 | });
42 |
43 | //add various style on selector
44 | document.querySelector(".easy_slider").style.display = "none";
45 |
46 |
47 | //add various style on selector
48 | document.querySelector(selector).style.backgroundSize = "cover";
49 | document.querySelector(selector).style.backgroundRepeat = "no-repeat";
50 | document.querySelector(selector).style.backgroundPosition = "center center";
51 |
52 |
53 | setTimeout(function() {
54 | //add various style on selector
55 | if (typeof sld_args.transition_timing === 'undefined') {
56 | sld_args.transition_timing = "ease-in";
57 | }
58 | if (typeof sld_args.transition_duration === 'undefined') {
59 | sld_args.transition_duration = 500;
60 | }
61 | var transition = "all " + sld_args.transition_duration + 'ms ' + sld_args.transition_timing;
62 | document.querySelector(selector).style.WebkitTransition = transition;
63 | document.querySelector(selector).style.MozTransition = transition;
64 | document.querySelector(selector).style.MsTransition = transition;
65 | document.querySelector(selector).style.OTransition = transition;
66 | document.querySelector(selector).style.transition = transition;
67 | }, 100);
68 |
69 |
70 | //this n is number of row in object - if first row one function if more than 1 then other
71 | var n = 1;
72 | //li collection previous delays from previous slides
73 | var li = 0;
74 |
75 | function slider() {
76 | //switching all images one by one
77 | sld_args.slide.forEach(function(vvv, iii) {
78 | //here go all slides except first
79 | if (n > 1) {
80 | //set delay from collected number from previous slides
81 | var delay = li;
82 | setTimeout(function() {
83 |
84 | document.querySelector(selector).style.backgroundImage = "url('" + vvv + "')";
85 |
86 | }, delay); // >1
87 | //collecting delays from curent
88 | li = li + sld_args.delay[iii];
89 |
90 | } else { //this function for only first slide
91 |
92 | //next row
93 | n++;
94 | //collect delay first time
95 | li = sld_args.delay[iii];
96 |
97 | document.querySelector(selector).style.backgroundImage = "url('" + vvv + "')";
98 |
99 | }
100 |
101 | });
102 |
103 | };
104 |
105 | slider();
106 |
107 | setInterval(function() { // REPEAT
108 |
109 | slider();
110 | //here used length of array of delays in object instead you tot_time variable
111 | }, sld_args.delay.length);
112 |
113 | }
114 |
--------------------------------------------------------------------------------