So I have setup a slick carousel in my shopify page, I ran into an issue though. So I have 5 slides set up. When the slick carousel loads, it puts blank slides between my actual slides.
How do I get rid of them?
Here is how it looks:
Here's my code:
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js" integrity="sha512-XtmMtDEcNz2j7ekrtHvOVR4iwwaD6o/FUJe6+Zq+HgcCsk3kj4uSQQR8weQ2QVj1o0Pk6PwYLohm206ZzNfubg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css" integrity="sha512-wR4oNhLBHf7smjy0K4oqzdWumd+r5/+6QO/vDda76MW5iug4PT7v86FoEkySIJft3XA0Ae6axhIvHrqwm793Nw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="slider-container">
<div class="image-container Pre_slide">
{% for block in section.blocks %}
<div class="image-title">
{{ block.settings.slide_title }}
</div>
<div class="slider-image">
<img src="{{ block.settings.slide_image | img_url: 'master' }}">
</div>
{% endfor %}
</div>
</div>
<script>
$('.image-container').slick({
slidesToShow: 3,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 2000,
});
</script>
{% schema %}
{
"name": "Carousel Slider",
"tag": "section",
"class": "slideshow",
"max_blocks": 5,
"settings": [
{
"type": "text",
"id": "title",
"label": "Slideshow"
},
{
"type": "liquid",
"id": "custom_liquid",
"label": "t:sections.custom-liquid.settings.custom_liquid.label"
}
],
"blocks": [
{
"name": "Slide",
"type": "slide",
"settings": [
{
"type": "image_picker",
"id": "slide_image",
"label": "Image"
},
{
"type": "text",
"id":"slide_title",
"label":"Title"
}
]
}
],
"presets": [
{
"name": "Carousel Slider"
}
]
}
{% endschema %}
<style>
.slider-container {
margin-bottom: 50vh;
}
.image-container {
display: flex;
flex-direction: row;
justify-content: center;
}
.slider-image {
padding: 0 1vw 0 1vw;
}
.slider-image img {
border-radius: 10px;
}
</style>
So because of the word/code ratio I have to put some extra details so here I go. Ive been trying to make a slideshow kinda thing where it automatically slides from one item to another... well it was all going well until this bug/glitch/issue popped up... so here I am asking for your help.
Thank you in advance!
You have to wrap one slide into one single DIV:
<div class="new-single-slide-div">
<div class="image-title">
{{ block.settings.slide_title }}
</div>
<div class="slider-image">
<img src="{{ block.settings.slide_image | img_url: 'master' }}">
</div>
</div>
Slick Carousel makes a slide for each div inside the given selector on the .slick() call.
Your calling $('.image-container').slick();
inside your HTML shopify markup {% for block in section.blocks %}. This generates two divs, first the text and second the image. This will generate 2 slides, instead your expected single slide.
Related
So to explain my situation: I am trying to build a page on shopify wherein images will appear like so:
Right. So I have tried to build a shopify section where trough the shopify website customizer you are supposed to be able to put in images and it should appear like the image.
The issue is: With the current code that I have, the first 3 images work really nicely and appear next to eachother, but when I go to make another block and add 3 new pictures, they appear like so:
I only want 3 images on the page, not more. I want it to appear under the first 3, and then the next 3 to also appear under the last 3 etc etc etc.
Here is my code:
<div class="gallery">
<div class="col">
{% for block in section.blocks %}
<div class="image">
<img src="{{ block.settings.editorial_image | img_url: 'master' }}">
</div>
</div>
<div class="col">
<div class="image">
<img src="{{ block.settings.editorial_image2 | img_url: 'master' }}">
</div>
</div>
<div class="col">
<div class="image">
<img src="{{ block.settings.editorial_image3 | img_url: 'master' }}">
</div>
</div>
{% endfor %}
</div>
{% schema %}
{
"name": "EditorialTest2",
"tag": "section",
"class": "gallery",
"max_blocks": 9,
"settings": [
{
"type": "text",
"id": "title",
"label": "Editorial"
}
],
"blocks": [
{
"name": "PictureBlock",
"type": "slide",
"settings": [
{
"type": "image_picker",
"id": "editorial_image",
"label": "Image"
},
{
"type": "image_picker",
"id": "editorial_image2",
"label": "Image"
},
{
"type": "image_picker",
"id": "editorial_image3",
"label": "Image"
}
]
}
],
"presets": [
{
"name": "Editorial Section Test 2"
}
]
}
{% endschema %}
<style>
.gallery {
display: flex;
}
#media only screen and (max-width: 560px) {
.gallery {
flex-direction: column;
}
}
.image img {
width: 100%;
}
</style>
.row {
width: 100%;
display: flex;
height: 100%;
}
.columns {
width: 33%;
display: flex;
flex-direction: column;
height: 100%;
}
.red {
background: red;
}
.blue {
background: blue;
}
<div class="row">
<div class="columns red">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png">
</div>
<div class="columns blue"> <img src="https://www.seiu1000.org/sites/main/files/main-images/camera_lense_0.jpeg">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png">
</div>
<div class="columns red"> <img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/Image_created_with_a_mobile_phone.png">
<img src="https://www.seiu1000.org/sites/main/files/main-images/camera_lense_0.jpeg">
<img src="https://www.seiu1000.org/sites/main/files/main-images/camera_lense_0.jpeg">
</div>
</div>
here is a simple demostration using flex, hope it can help
i have section about.liquid and
<section class="about" id="bg-image">
inside. Also i have shema:
{% schema %}
{
"name": "About background",
"settings": [],
"blocks":[
{
"type": "image",
"name": "About background",
"settings": [
{
"type": "image_picker",
"id": "bg-image",
"label": "Custom Background Image"
}
]
}
],
"presets": [
{
"category": "image",
"name": "main images"
}
]
}
{% endschema %}
and style tag:
<style>
#bg-image {
background-image:url('{{ section.blocks.settings.bg-image.src | img_url: 'master' }}');
background-size: cover;
}
</style>
Why doesn't it work? In output i have image with caption "No image"
<section class="image-slider">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
{% for block in section.blocks %}
<li data-target="#carouselExampleIndicators" data-slide-to="{{forloop.index0}}" {%if forloop.index0 == 0 %} class="active" {% endif %}></li>
{% endfor %}
</ol>
<div class="carousel-inner">
{% for block in section.blocks %}
<div class="carousel-item {% if forloop.first %} active {% endif %} ">
<img src="{{block.settings.image | img_url: 'master'}}">
<div class="carousel-caption d-none d-md-block">
<h5 class="title-color">{{block.settings.title}}</h5>
</div>
</div>
<style>
.title-color{
color: {{ block.settings.title_color }};
}
</style>
{% endfor %}
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</section>
{% schema %}
{
"name": "Image Slider",
"max_blocks": 5,
"settings": [
{
"type": "header",
"content": "Image Slider"
}
],
"blocks": [
{
"type": "image",
"name": "Image",
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "Image"
},
{
"type": "text",
"id": "title",
"label": "Image Title"
},
{
"type": "color",
"id": "title_color",
"label": "Title Color",
"default": "#ffffff"
}
]
}
],
"presets": [
{
"category": "Image",
"name":"Image Slider"
}
]
}
{% endschema %}
I am learning shopify and encounter a problem regarding getting css font color. It is working fine I am able to select font color from color picker and it is applying on my slide but the problem is when i add new slide and change its title font color it applies color plus overrides previous slide title color also and applies the new slide title color to all slides . I know i am missing something here . I want my slide title color different for every slide as well as other font styles.
If you use the {{ forloop.index }} when iterating the loop, you can dynamically assign it to HTML header and your CSS class. That way, each block h5 will have its own color class.
<h5 class="title-color-{{ forloop.index }}">{{block.settings.title}}</h5>
.title-color-{{ forloop.index }} {
color: {{ block.settings.title_color }};
}
As the loop progresses, you are gradually building up dynamic HTML and CSS.
first run
<h5 class="title-color-1">block title</h5>
.title-color-1 {
color: #block-color;
}
second run
<h5 class="title-color-2">block title</h5>
.title-color-2 {
color: #block-color;
}
Notice how each block's h5 class and CSS is now unique via its index and, therefore, not overwritten by new blocks.
Hey Guys I have the following code which loops the <section> everytime I use it within the JSON. This works fine.
However, I am having problems with the nested loop {% for list in lists %} which handles the li elements. It comes out blank and seems to only loop twice when I inspect the element?
{# Question 1 #}
{% for question in questions %}
<section>
<div class="container question" id="question-one">
<div class="row row-eq-height">
<div class="gradient"></div>
<div class="col-md-1 green-box">
<div class="number"><span>1</span></div>
</div>
<div class="col-md-10 dark-grey-box text-center">
<div class="content-wrapper">
{{ question.text|markdown }}
{# SLIDER #}
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="slider-container">
<ul class="list-inline justify-content-center range-labels">
{% for list in lists %}
<li class="list-inline-item"><img src="{{ list.img }}"><span>{{ list.label }}</span></li>
{% endfor %}
</ul>
<div class="range-wrapper">
<img src="../resources/images-assets/images/place-holder-slider.png">
</div>
</div>
</div>
</div>
<div class="cta-wrapper">
<button id="question-one-submit" onclick="buttonClick()">DONATE £1</button>
</div>
</div>
</div>
<div class="col-sm-1 dark-grey-box"></div>
</div>
</div>
</section>
{% endfor %}
In my JSON file I have laid everything out as follows:
"questions": [
{
"text": "##How confident are you in achieving your marketing goals this year?",
"lists": [
{ "img": "..\/resources\/images-assets\/images\/sad.svg", "label": "Dejected" },
{ "img": "..\/resources\/images-assets\/images\/sad.svg", "label": "Dejected" },
{ "img": "..\/resources\/images-assets\/images\/sad.svg", "label": "Dejected" },
{ "img": "..\/resources\/images-assets\/images\/sad.svg", "label": "Dejected" },
{ "img": "..\/resources\/images-assets\/images\/sad.svg", "label": "Dejected" }
]
}
],
I want the li to appear 5 times with the relevant image and label as I have added in the JSON file.
Can anyone point me in the right direction?
I managed to get this working correctly. Here is the markup:
{% for question in questions %}
<section>
<div class="container question" id="question-{{ loop.index }}">
<div class="row row-eq-height">
<div class="gradient"></div>
<div class="col-md-1 green-box">
<div class="number"><span>
{{ loop.index }}
</span></div>
</div>
<div class="col-md-10 dark-grey-box text-center">
<div class="content-wrapper">
{{ question.text|markdown }}
{# SLIDER #}
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="slider-container">
<ul class="list-inline justify-content-center range-labels">
{% for option in question.options %}
<li class="list-inline-item"><img src="{{ option.img }}"><span>{{ option.label }}</span></li>
{% endfor %}
</ul>
<div class="range-wrapper">
<img src="images/place-holder-slider.png">
</div>
</div>
</div>
</div>
<div class="cta-wrapper">
<button id="button-{{ loop.index }}" onclick="buttonClick()">{{ question.button }}</button>
</div>
</div>
</div>
<div class="col-sm-1 dark-grey-box"></div>
</div>
</div>
</section>
{% endfor %}
The JSON file I am using to accompany this is as follows:
"questions": [
{
"text": "##How confident are you in achieving your marketing goals this year?",
"options": [
{ "img": "images/sad.svg", "label": "Dejected" },
{ "img": "images/thinking-2.svg", "label": "Doubtful" },
{ "img": "images/like.svg", "label": "Hopeful" },
{ "img": "images/check.svg", "label": "Upbeat" },
{ "img": "images/goal.svg", "label": "Surefire" }
],
"button": "DONATE £1"
},
{
"text": "##What are the greatest challenges you face?",
"options": [
{ "img": "images/money-bag.svg", "label": "Budget" },
{ "img": "images/team.svg", "label": "Resources" },
{ "img": "images/bar-chart.svg", "label": "ROI" },
{ "img": "images/timer.svg", "label": "Short-termis" },
{ "img": "images/martech.svg", "label": "Martech" }
],
"button": "DONATE £1"
},
{
"text": "##Where could external agencies add the most value?",
"options": [
{ "img": "images/networking.svg", "label": "ABM" },
{ "img": "images/increasing-stocks-graphic-of-bars.svg", "label": "Demand" },
{ "img": "images/options.svg", "label": "Strategy" },
{ "img": "images/full-items-inside-a-shopping-bag.svg", "label": "Sales Enablement" },
{ "img": "images/content.svg", "label": "Content" }
],
"button": "DONATE £1"
},
{
"text": "##Would you be interested in a further conversation?",
"options": [
{ "img": "images/thumb-down.svg", "label": "Don't contact me again" },
{ "img": "images/maybe.svg", "label": "Unlikely this year" },
{ "img": "images/info.svg", "label": "Need to know more" },
{ "img": "images/calendar.svg", "label": "Get a date in the diary" },
{ "img": "images/boy-broad-smile.svg", "label": "Call me now" }
],
"button": "DONATE £1"
}
],
i have a video within the Fresca CMS page as below
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="https://content.jwplatform.com/libraries/ovBRFdgO.js"></script>
<div class="container u-spacer-v">
<div class="row">
<div class="col-lg-12 spacer50">
<div class="videoWrapper">
<div id="media_player"></div>
<script type="text/javascript">
var playerInstance;
$(document).ready(function () {
playerInstance = jwplayer("media_player").setup({
"playlist": [{
"sources": [{
"file": "http://content.jwplatform.com/videos/tNGbzoVc-F67Awtrj.mp4",
}],
"tracks": [{
"file": "https://content.jwplatform.com/tracks/YFoEjMQx.vtt",
"label": "English",
"kind": "captions"
}]
}],
"captions": {
"color": "FE94AB",
"backgroundColor": "000000",
"backgroundOpacity": 100,
"fontSize": 8
},
"autostart": false,
"controls": true,
"primary": "flash",
"aspectratio": "16:9"
});
/*
playerInstance.on('ready', function () {
$('#status').html("JW7. Provider name: " + playerInstance.getProvider().name);
});
*/
playerInstance.on('captionsList', function (t) {
console.log(t)
});
});
</script>
</div>
</div>
</div>
i would like to make this responsive. i have
<div class="videoWrapper">
<div id="media_player"></div>
which ordinarily would deal with it but because id="media_player" forces the player to have a size i am not able to work round this. does anyone have an idea on how to achieve responsiveness please?
cheers
In your css add this:
#media (max-width: 767px) {
.videoWrapper {
width: 100%;
}
#media_player {
width: 100%;
}
#media_player
{
width: 100%;
}
}