I have problems viewing the range uislider on ios and android
In an application with meteor and cordova, in the following video I leave to the detail. When moving the slider in the browser works but in ios and android I can not visualize the ranges obtained.
I have the following code:
Try with jquery as you can see that the code is commented and I did not get results
Template.range.onRendered(function () {
$(function () {
$('#slider-edad').noUiSlider({
start: [18, 30],
step: 1,
range: {
'min': 18,
'max': 60
}
});
});
$(function () {
$('#range').noUiSlider({
start: [10],
step: 2,
range: {
'min': 10,
'max': 100
}
});
});
// km();
});
function km(instance) {
// $('.km-range').html('');
// Session.set("Kilometros", '');
var d1 = $('#range').val();
var d0r = parseInt(d1);
console.log('Kilometros: ', d0r);
instance.km1.set(d0r);
// Session.set("Kilometros", d0r);
// $('.km-range').html(d0r, 'Km');
}
Template.range.events({
'click #range': function (event, instance) {
console.log('click');
km(instance);
},
});
After a long chat and many tries it turned out to be the click event, that makes the noUiSlider not work on mobile.
So checking on the noUiSlider events page and putting this into some reactive variables we got the following code running:
import { Template } from 'meteor/templating';
import { ReactiveDict } from 'meteor/reactive-dict';
//import template html file
Template.findme.onCreated(function (){
this.state = new ReactiveDict();
// set start values
this.state.set("km", 10);
this.state.set("agemin", 18);
this.state.set("agemax", 30);
});
Template.findme.onRendered(function() {
if (!this._rendered) {
this._rendered = true;
// create slider
$('#slider-edad').noUiSlider({
start: [ 18, 30 ],
step: 1,
range: {
'min': 18,
'max': 60
}
})
$('#range').noUiSlider({
start: [ 10 ],
step: 2,
range: {
'min': 10,
'max': 100
}
});
}
});
Template.findme.helpers({
KilosM: function(){
return Template.instance().state.get("km");
},
agemin: function(){
return Template.instance().state.get("agemin");
},
agemax: function(){
return Template.instance().state.get("agemax");
},
});
Template.findme.events({
'slide #slider-edad':function(event,instance) {
var d2= $('#slider-edad').val()
var d0 = parseInt(d2[0]);
var d1 = parseInt(d2[1]);
console.log(d0,d1);
instance.state.set("agemin", d0);
instance.state.set("agemax", d1);
} ,
'slide #range': function(event , instance) {
var d1= $('#range').val();
var d0r = parseInt(d1);
console.log('Kilometros: ',d0r);
instance.state.set("km", d0r);
},
});
and the html template being:
<div class="">
<span class="edad-range0">{{agemin}}</span>
<span class="edad-title"> Age </span>
<span class="edad-range1">{{agemax}}</span><br>
<div id="slider-edad"></div><br><br>
</div>
Related
In my sprite sheet I have two separate frames for when the character is not moving, one is for when she was moving left and then stopped and the other for when she was moving right and then stopped, so i need it to fire up on sort of a key up event. I've seen very similar question here, but the answer didn't work for me, it said to add:
scene.input.keyboard.on('keyup-LEFT', function()
{
});
but it just broke my code, screen goes black and nothing happens, i tried adding that code in either create() and update()
So i tried instead:
this.input.keyboard.on('keyup-LEFT', function()
{
player.setVelocityX(0);
player.anims.play('stopLeft');
});
this.input.keyboard.on('keyup-RIGHT', function()
{
player.setVelocityX(0);
player.anims.play('stopRight');
});
It doesn't break my code, but also nothing happens, I also tried player instead of scene or this, (player is a variable to which my sprite is assigned), but that also broke my code, just like scene did.
BTW, stopLeft and stopRight works fine, because i tested them on normal this.input.keyboard.createCursorKeys() events.
The most common way to implement player movement and/or input is, to put the logic in the update function, and check if the keys are pressed/down (isDown).
I would only use this.input.keyboard, for hot-key like 'ESC' or some special hot-keys.
Here a short working demo:
(for more details checkout this official example)
document.body.style = 'margin:0;';
var config = {
type: Phaser.AUTO,
width: 536,
height: 183,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 100 }
}
},
scene: {
preload,
create,
update
},
banner: false
};
let player;
let cursor;
let animsKeyText;
function preload() {
this.load.spritesheet('dude', 'https://labs.phaser.io/src/games/firstgame/assets/dude.png', { frameWidth: 32, frameHeight: 48 });
}
function create() {
let floor = this.add.rectangle(0, config.height, config.width, 20, 0xcdcdcd)
.setOrigin(0, .5);
animsKeyText = this.add.text(10, 10, 'current anims-key: ??')
this.physics.add.existing(floor, true);
player = this.physics.add.sprite(100, 10, 'dude')
.setCollideWorldBounds(true);
this.anims.create({
key: 'left',
frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'right',
frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 8 }),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: 'stop-left',
frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 1 }),
frameRate: 10,
repeat: 0
});
this.anims.create({
key: 'stop-right',
frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 6 }),
frameRate: 10,
repeat: 0
});
this.physics.add.collider(player, floor);
cursors = this.input.keyboard.createCursorKeys();
}
function update() {
if (cursors.left.isDown) {
player.setVelocityX(-160);
player.anims.play('left', true);
}
else if (cursors.right.isDown) {
player.setVelocityX(160);
player.anims.play('right', true);
}
else {
player.setVelocityX(0);
if (player.anims && player.anims.currentAnim) {
// just to prevent of keys "stop-stop....-right" or so
if (player.anims.currentAnim.key.indexOf('stop') == -1) {
let newKey = `stop-${player.anims.currentAnim.key}`;
player.anims.play(newKey, true);
}
}
}
if (player.anims && player.anims.currentAnim) {
animsKeyText.setText(`current anims-key: ${player.anims.currentAnim.key}`);
}
}
new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/phaser#3.55.2/dist/phaser.js"></script>
I'm trying to figure out how to implement an autoplay function in a jquery script called Momentum Slider (link and demo), this script creates a horizontal slider that could be used for displaying things like related posts, so I tried using this resource Jquery image slider auto play, but with no success. How can I achieve that?
(function() {
var slidersContainer = document.querySelector('.sliders-container');
// Initializing the numbers slider
var msNumbers = new MomentumSlider({
el: slidersContainer,
cssClass: 'ms--numbers',
range: [1, 4],
rangeContent: function (i) {
return '0' + i;
},
style: {
transform: [{scale: [0.4, 1]}],
opacity: [0, 1]
},
interactive: false
});
// Initializing the titles slider
var titles = [
'King of the Ring Fight',
'Sound of Streets',
'Urban Fashion',
'Windy Sunset'
];
var msTitles = new MomentumSlider({
el: slidersContainer,
cssClass: 'ms--titles',
range: [0, 3],
rangeContent: function (i) {
return '<h3>'+ titles[i] +'</h3>';
},
vertical: true,
reverse: true,
style: {
opacity: [0, 1]
},
interactive: false
});
// Initializing the links slider
var msLinks = new MomentumSlider({
el: slidersContainer,
cssClass: 'ms--links',
range: [0, 3],
rangeContent: function () {
return '<a class="ms-slide__link">View Case</a>';
},
vertical: true,
interactive: false
});
// Get pagination items
var pagination = document.querySelector('.pagination');
var paginationItems = [].slice.call(pagination.children);
// Initializing the images slider
var msImages = new MomentumSlider({
// Element to append the slider
el: slidersContainer,
// CSS class to reference the slider
cssClass: 'ms--images',
// Generate the 4 slides required
range: [0, 3],
rangeContent: function () {
return '<div class="ms-slide__image-container"><div class="ms-slide__image"></div></div>';
},
// Syncronize the other sliders
sync: [msNumbers, msTitles, msLinks],
// Styles to interpolate as we move the slider
style: {
'.ms-slide__image': {
transform: [{scale: [1.5, 1]}]
}
},
// Update pagination if slider change
change: function(newIndex, oldIndex) {
if (typeof oldIndex !== 'undefined') {
paginationItems[oldIndex].classList.remove('pagination__item--active');
}
paginationItems[newIndex].classList.add('pagination__item--active');
}
});
// Select corresponding slider item when a pagination button is clicked
pagination.addEventListener('click', function(e) {
if (e.target.matches('.pagination__button')) {
var index = paginationItems.indexOf(e.target.parentNode);
msImages.select(index);
}
});
})();
How i can draw data-id for each column item in my function updateIndices simillar to updateColumnIndices?
I want to make my grid more dynamic.
I using only javascript and Muuri lib for drag and drop.
Thank you for help.
Muuri is a JavaScript layout engine that allows you to build all kinds of layouts and make them responsive, sortable, filterable, draggable and/or animated. Comparing to what's out there Muuri is a combination of Packery, Masonry, Isotope and Sortable. Wanna see it in action? Check out the demo on the website.
My code for this task under spoiler
function setupItemContainer() {
let itemContentContainer = document.querySelectorAll('.board-column-content');
for(let i = 0; i < itemContentContainer.length; i++)
{
if(!itemContentContainer[i].classList.contains('muuri'))
{
itemContainers.push(itemContentContainer[i]);
muuriItems = new Muuri(itemContentContainer[i], {
itemDraggingClass: 'muuri-item-default-dragging',
dragSortHeuristics: {
sortInterval: 10,
minDragDistance: 5,
minBounceBackAngle: Math.PI / 2
},
dragPlaceholder: {
enabled: true,
duration: 100,
easing: 'ease',
createElement: null,
onCreate: null,
onRemove: null
},
items: '.board-item',
layoutDuration: 400,
layoutEasing: 'ease',
dragEnabled: true,
dragSort: function () {
return columnGrids;
},
dragSortInterval: 0,
dragContainer: document.body,
dragReleaseDuration: 400,
dragReleaseEasing: 'ease',
itemPlaceholderClass: 'muuri-item-placeholder'
})
.on('dragStart', function (item) {
item.getElement().style.width = item.getWidth() + 'px';
item.getElement().style.height = item.getHeight() + 'px';
})
.on('dragReleaseEnd', function (item) {
item.getElement().style.width = '';
item.getElement().style.height = '';
columnGrids.forEach(function (muuriItems) {
muuriItems.refreshItems();
});
})
.on('layoutStart', function () {
muuriColumns.refreshItems().layout();
})
.on('move', updateIndices)
.on('sort', updateIndices);
columnGrids.push(muuriItems);
}
}
}
function setupColumnsContainer() {
muuriColumns = new Muuri(gridElement, {
itemDraggingClass: 'muuri-item-column-dragging',
layoutDuration: 400,
layoutEasing: 'ease',
dragEnabled: true,
dragSortInterval: 0,
dragStartPredicate: {
handle: '.board-column-header'
},
dragReleaseDuration: 400,
dragReleaseEasing: 'ease',
})
.on('move', updateColumnIndices)
.on('sort', updateColumnIndices);
}
function updateColumnIndices() {
muuriColumns.getItems().forEach(function (item, i) {
item.getElement().setAttribute('data-id', i);
});
}
function updateIndices() {
muuriItems.getItems().forEach(function (item, i) {
item.getElement().setAttribute('data-id', i);
});
}
I am using jquery to refresh my JustGage gauges. I get my data back from the controller and everything works just fine until eventually the pc runs out of memory and it freezes. I have 9 gauges and 2 pie charts that need refreshing. The setInterval call is the problem, as it fires every second instead of waiting 120000 ms. Am I doing something wrong with setInterval?
<script>
window.onload = function () {
var g9 = new JustGage({
id: "gage9",
value: '#ViewBag.TotalNeuro',
min: 0,
max: 150,
counter: true,
label: "Total Neuro",
labelMinFontSize: 11,
formatNumber: true,
customSectors: {
//percents: true,
ranges: [
{ lo: 0, hi: 33, color: '#f0f016' }, // lo and hi values are in %
{ lo: 34, hi: 67, color: '#f59a1b' },
{ lo: 68, hi: 100, color: '#e0121c' }
]
},
levelColorsGradient: false,
gaugeWidthScale: 0.9,
startAnimationTime: 2700,
startAnimationType: "bounce",
});
setInterval(function () {
var TotalNeuroUrl = '#Url.Action("TotalNeuro")';
$.getJSON(TotalNeuroUrl, {}, function (dataNeuro) {
g9.refresh(dataNeuro);
}, 120000);
});
};
It seems that you use setInterval incorrectly, refer to https://www.w3schools.com/jsref/met_win_setinterval.asp
Try to modify it to:
setInterval(function () {
var TotalNeuroUrl = '#Url.Action("TotalNeuro")';
$.getJSON(
TotalNeuroUrl,
{},
function (dataNeuro) {
g9.refresh(dataNeuro);
}
);
},120000);
I am displaying jqplot meter gauge inside modal window and I want to update it after every 5 seconds. I wrote the following code but it is not working
$(document).ready(function(){
s1 = [Math.floor(Math.random()*(401)+100)];
plot3 = $.jqplot('meter',[s1],{
seriesDefaults: {
renderer: $.jqplot.MeterGaugeRenderer,
rendererOptions: {
min: 100,
max: 500,
intervals:[200, 300, 400, 500],
intervalColors:['#66cc66', '#93b75f', '#E7E658', '#cc6666'],
smooth: true,
animation: {
show: true
}
}
}
});
$('a[href=\"#yw1_tab_3\"]').on('shown', function(e) {
if (plot3._drawCount === 0) {
plot3.replot();
}
});
windows.setInterval(function() { plot3.destroy();
s1 = [Math.floor(Math.random()*(401)+100)];
plot3.replot();
}, 5000);
});
How can I update meter gauge every 5 seconds without updating whole page?
here is the fix: JsFiddle link
$(document).ready(function () {
var s1 = [Math.floor(Math.random() * (401) + 100)];
var plot3 = $.jqplot('meter', [s1], {
seriesDefaults: {
renderer: $.jqplot.MeterGaugeRenderer,
rendererOptions: {
min: 100,
max: 500,
intervals: [200, 300, 400, 500],
intervalColors: ['#66cc66', '#93b75f', '#E7E658', '#cc6666'],
smooth: true,
animation: {
show: true
}
}
}
});
setInterval(function () {
s1 = [Math.floor(Math.random() * (401) + 100)];
plot3.series[0].data[0] = [1,s1]; //here is the fix to your code
plot3.replot();
}, 1000);
});