How to parent this range slider with image zooming for website? (HTML/CSS/JavaScript) - javascript

I'm using Sublime Text 3 and have been attempting to make this range slider zoom in and out of a website to make it interactive to visitors. The code seems to work here, but not on Sublime Text 3.
Are there any tips on how to fix this?
var zoomer = document.getElementById('zoomer');
var spacepic = document.getElementById('spacepic');
function deepdive(){
zoomlevel = zoomer.valueAsNumber;
spacepic.style.webkitTransform = "scale("+zoomlevel+")";
pic.style.transform = "scale("+zoomlevel+")";
}
/*Image Test 1*/
#milkyway-container {
width: 100%;
font-size: 0;
border: 1px solid #111;
overflow: hidden;
margin: 0 auto;
margin-top: 2rem;
}
#spacepic {
width: 100%;
}
#zoomer {
display: block;
width: 30%;
margin: 7rem auto;
}
#media all and (max-width: 500px) {
#zoomer, #milkyway-container {
width: 85%;
}
}
<!DOCTYPE html >
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ORIGINS</title>
<link rel="stylesheet" href="style.css"
<base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
<script>
<script src="app.js"></script>
</script>
</head>
<body>
</div>
<div id="milkyway-container">
<img src="https://images.pexels.com/photos/1252890/pexels-photo-1252890.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" alt="Milkyway Photo" id="spacepic">
<input type="range" min="1" max="4" value="1" step="0.1" id="zoomer" oninput="deepdive()">
</div>
</body>
</html>

Related

Javascript - Search and highlight words in a text (mixed or in a row)

I am trying to find a javascript code for a word searcher in a text (through a form and a search button). Ι have found one which can search many words at the same time, but they need to be in a row. If the words are mixed it doesn't work. What kind of updates should we make?
Please advise
My regards
my code
`
<!DOCTYPE html>
<html lang="en">
<title>Word finder</title>
<head>
<meta charset="UTF-8" />
<title>Text Finder</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css" />
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght#500&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
* {
padding: 0;
margin: 0;
outline: 0;
font-family: 'IBM Plex Sans', sans-serif;
}
body {
height: 100vh;
width: 100vw;
overflow: hidden;
}
.content {
width: 80%;
margin: 50px auto;
}
h1 {
text-align: center;
}
.form {
display: flex;
align-items: center;
justify-content: center;
margin: auto;
width: 100%;
max-width: 320px;
height: 50vh;
}
input#keyword {
font-size: 18px;
padding: 10px 20px;
outline: 0;
border: 1px solid #0f62fe;
width: auto;
}
span.highlight {
color: black; background-color:yellow;
text-shadow: 0 1px 1px red;
}
</style>
</head>
<body>
<div class="content">
<p>English texts for beginners to practice reading and comprehension online and for free. Practicing your comprehension
of written English will both improve your vocabulary and understanding of grammar and word order. The texts below are designed
to help you develop while giving you an instant evaluation of your progress.</p>
</div>
<h1>Find the word in paragraph</h1>
<div class="form">
<input type="text" id="keyword" class="form_control" placeholder="Search...">
</div>
<script>
function textFind(keyword) {
if(keyword) {
var content = $("p").text();
var searchText = new RegExp(keyword, "ig");
var matches = content.match(searchText);
if(matches) {
$("p").html(content.replace(searchText, function(match){
return "<span class='highlight'>"+match+"</span>";
}));
}else {
$('.highlight').removeClass('highlight');
}
}else{
$('.highlight').removeClass('highlight');
}
}
$(document).ready(function(){
$('#keyword').on('keyup', function(){
textFind($(this).val());
})
});
</script>
</body>
</html>
`
To search many words mixed
As I don't exactly know what methods you would like to use. I can't fully answer.
But take a look at this js method: https://www.w3schools.com/jsref/jsref_includes.asp

How to prevent child div overflow out of parent div on changing CSS zoom property?

I know we can prevent overflow of child content using CSS overflow property.
But the overflow: scroll property is not preventing overflow.
let zoomInElem = document.getElementById('zoomIn')
let zoomOutElem = document.getElementById('zoomOut')
let contentElement = document.getElementById('content')
zoomInElem.addEventListener('click', function () {
console.log('zoomIn')
contentElement.style.zoom = '200%'
})
zoomOutElem.addEventListener('click', function () {
console.log('zoomOut')
contentElement.style.zoom = '100%'
})
#main {
width: 640px;
height: 360px;
border: solid;
}
#content {
border: .1rem solid red;
overflow: scroll;
}
button {
margin: 1rem;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<style>
</style>
</head>
<body>
<div>
<button id="zoomIn">ZoomIn</button>
<button id="zoomOut">ZoomOut</button>
</div>
<div id="main">
<div id="content">
<h1>Hi</h1>
<h2>Hi</h2>
<h3>Hi</h3>
<h4>Hi</h4>
</div>
</div>
<script>
</script>
</body>
</html>
How can I prevent overflow on changing CSS zoom property by clicking ZoomIn button?
Try To Set overflow: scroll; on outer div
#main { position: relative;overflow: scroll;}
You can either define the width and height of #content, or set the overflow of #main to scroll.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<style>
#main {
width: 640px;
height: 360px;
border: solid;
overflow: scroll;
}
#content {
/*width: 100%;
height: 100%; */
border: .1rem solid red;
/* overflow: scroll; */
}
button {
margin: 1rem;
}
</style>
</head>
<body>
<div>
<button id="zoomIn">ZoomIn</button>
<button id="zoomOut">ZoomOut</button>
</div>
<div id="main">
<div id="content">
<h1>Hi</h1>
<h2>Hi</h2>
<h3>Hi</h3>
<h4>Hi</h4>
</div>
</div>
<script>
let zoomInElem = document.getElementById('zoomIn')
let zoomOutElem = document.getElementById('zoomOut')
let contentElement = document.getElementById('content')
zoomInElem.addEventListener('click', function () {
contentElement.style.zoom = '200%'
})
zoomOutElem.addEventListener('click', function () {
contentElement.style.zoom = '100%'
})
</script>
</body>
</html>

How to increase height of div from top not from bottom?

I am trying to increase height of div on button click. I am facing an issue my div is increase from bottom (default behaviour). But I want my div bottom with remain contain. It show from top.
In my example I have two div yellow and white. On button click, I am increasing the height of white box. But it is increase from down direction. I need it grows from top.
Here is my code:
https://codesandbox.io/s/still-lake-lw07u?file=/index.html
<body>
<div class="parent">
<div class="abc">
<div class="img"></div>
<div class="content"></div>
</div>
</div>
<button onclick="abc()">click</button>
<script>
function abc() {
document.querySelector(".content").style.height = "300px";
}
</script>
</body>
Unclear of final design, but you might try this:
function abc() {
const sel = document.querySelector(".content");
sel.style.height = "300px";
sel.style.position = 'absolute';
sel.style.bottom = '0px';
}
You can use the transform: scaleY(val) and transform-origin: bottom to resize and from where your element.
.abc {
width: 80%;
margin: auto;
display: grid;
grid-template-columns: repeat(10, [col-start] 1fr);
grid-template-rows: repeat(8, [row-start] 1fr);
padding-top: 3.4em;
padding-bottom: 3.4em;
}
.img {
grid-column: col-start / span 8;
grid-row: row-start / span 6;
background-size: cover;
max-width: 1074px;
max-height: 200px;
background-color: #ee0;
}
.content {
grid-column: col-start 6 / span 6;
grid-row: row-start 2 / span 6;
background: #fff;
min-height: 100px;
border: 1px solid blue;
padding: 3em;
}
.bigger {
transform: scaleY(2);
transform-origin:bottom;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Static Template</title>
<style>
</style>
</head>
<body>
<div class="parent">
<div class="abc">
<div class="img"></div>
<div class="content"></div>
</div>
</div>
<button onclick="abc()">click</button>
<script>
function abc() {
document.querySelector(".content").classList.add('bigger');
}
</script>
</body>
</html>
Another version:
<!DOCTYPE html><html lang="en"><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=yes"/>
<title> Test Page </title>
<!-- link rel="stylesheet" href="common.css" media="screen" -->
<!-- From: https://stackoverflow.com/questions/69050335/how-to-increase-height-of-div-from-top-not-from-bottom/69050592#69050592 -->
<style>
.content { background-color: pink; width: 10em; }
.asterisk { height: 300px; }
</style>
</head><body>
<div class="parent">
<div class="abc">
<div class="img">Image</div>
<div class="content">Content</div>
</div>
</div>
<button onclick="abc()">click</button>
<script>
function abc() {
const sel = document.querySelector(".content");
var div = document.createElement('div');
// div.innerHTML = '*';
div.className = 'asterisk';
sel.parentNode.insertBefore(div, sel);
}
</script>
</body></html>

Cannot adjust the height of container accordingly to the content [duplicate]

This question already has answers here:
What is a clearfix?
(10 answers)
What methods of ‘clearfix’ can I use?
(29 answers)
Closed 1 year ago.
I have this CSS project I am working on and now I am in the phase where I will start to embelish it with some effects and nice colors. However I just realized that there is a small issue with it: the beige container won't adjust its height as the blue cells move around. Could anyone help please? Here it is my code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="OEPanel.js"></script>
<link rel="stylesheet" href="./OEPanel.css">
<title>Document</title>
</head>
<body>
<div id="oepanelcontainer" class="OEContainer">
<div id="oepanel" class="OEItems">
<div id="oecell1" class="OECell"></div>
<div id="oecell2" class="OECell"></div>
<div id="oecell3" class="OECell"></div>
<div id="oecell4" class="OECell"></div>
</div>
</body>
</html>
CSS
.OEContainer {
background-color: beige;
min-height: 10em;
vertical-align: middle;
padding: 10px;
max-width:1130px;
margin:auto;
text-align:center;
justify-content:space-between;
}
.OEItems {
min-height: 10em;
vertical-align: middle;
padding: 0px;
max-width:1130px;
margin:auto;
text-align:center;
justify-content:space-between;
}
.OECell {
background-color: lightblue;
min-height: 10em;
vertical-align: middle;
padding: 0px;
width:250px;
text-align:center;
float: left;
margin: 5px;
}
#media (max-width: 500px) {
.OEContainer {
flex-direction: column;
align-items: center;
}
}
JS
// config
var __OECELLS = 4; // the total of oecells in HTML (oecell1, oecell2...)
var __CELLWIDTH = 250; // the width of cells in pixels
var __MAXSCREENWIDTH = 1130; // the maximum width of screen in pixels
var __MAXCELLS = parseInt(__MAXSCREENWIDTH/__CELLWIDTH);
var __ADJUSTMENT = (__CELLWIDTH-30)/2;
var __CELLSPERROW;
$(function() {
RedefinePanel();
});
$(window).resize(function() {
RedefinePanel();
});
function RedefinePanel() {
var viewportWidth = $(window).width();
let __CELLSPERROW = parseInt((viewportWidth-__ADJUSTMENT)/__CELLWIDTH);
document.getElementById("oepanel").style.width = ((__CELLSPERROW)*__CELLWIDTH+(__CELLSPERROW*17)) + "px";
Thanks!
You need a clearfix for the container of your floated items.
.OEContainer {
background-color: beige;
min-height: 10em;
vertical-align: middle;
padding: 10px;
max-width:1130px;
margin:auto;
text-align:center;
justify-content:space-between;
}
.OEItems {
min-height: 10em;
vertical-align: middle;
padding: 0px;
max-width:1130px;
margin:auto;
text-align:center;
justify-content:space-between;
}
.clearfix::after { /* clearfix class to expand the element back to its normal height */
content: '';
display: block;
clear: both;
}
.OECell {
background-color: lightblue;
min-height: 10em;
vertical-align: middle;
padding: 0px;
width:250px;
text-align:center;
float: left;
margin: 5px;
}
#media (max-width: 500px) {
.OEContainer {
flex-direction: column;
align-items: center;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="OEPanel.js"></script>
<link rel="stylesheet" href="./OEPanel.css">
<title>Document</title>
</head>
<body>
<div id="oepanelcontainer" class="OEContainer">
<div id="oepanel" class="OEItems clearfix"> <!-- clearfix class added here -->
<div id="oecell1" class="OECell"></div>
<div id="oecell2" class="OECell"></div>
<div id="oecell3" class="OECell"></div>
<div id="oecell4" class="OECell"></div>
</div>
</body>
</html>
When you use floats for all of the children of an element - it will collapse 0 height ( minus padding and margins etc ) unless you force it to expand to the size of it's children with a clearfix. Essentially it's a bug/quirk in browsers that's been persistent for a while.
Although this answers your questions I would advise against using floats wherever possible and use flexbox instead. Overall a lot less messy than floats in my opinion.

CSS- HELP Checkbox issue on widget

I've used a javaScript function to "build" a widget, call it on an HTML page and make it responsive using CSS.
Now, I've to use that same widget on an mvc.net application and i can't make it work like i want it. In the image shown bellow "aluger","venda", "compra" and "permuta" all show up in the same line, and I want them to show up on different lines. I've used display:block and nothing happend.
Those options are loaded automatic.
Can some one please help me?
CSS of DIV:
#div_maior {
display:block;
width: 100%;
height: 100%;
background-color: #ffffcc;
clear: both;
min-height: 50px;
max-height: 200px;
}
#div_global {
clear:left;
display:block;
float:left;
padding: .5%;
border-color: transparent;
height: 100%;
width: 30%;
// overflow: auto;
}
HTML OF THE WIDGET:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="javascript.js"></script>
<link rel="stylesheet" type="text/css" href="estilos.css"/>
</head>
<body id="body" onload="getFacetasAJAX()">
<label id="div_maior">
<label id="div_global" style="display: inline-block">
</label>
<label id="div_resultados" style="display: inline-block">
</label>
</label>
</body>
</html>

Categories

Resources