Need help :)

Diskutiere Need help :) im CSS Forum im Bereich Programmierung; Hi, so i'm recently getting into html, css and js. To experiment and see a little bit about what's possible, i found this cool animation...
  • Need help :) Beitrag #1
K
katko
Member
Beiträge
5
Punkte Reaktionen
0
Hi, so i'm recently getting into html, css and js.
To experiment and see a little bit about what's possible, i found this cool animation. (https://codepen.io/alvarotrigo/pen/YzYbdxV)
In order to try it out and understand how the code is structured/how it works, i copied the files into vs-code to run it on my computer.
Somehow i get a lot of errors in the css file and i don't understand why. Can someone maybe tell me what's the problem?

I tried to get rid of the errors by refactoring the code a little bit, but as i said im a beginner so im not 100% if its correct.

Thank!
 
  • Need help :) Beitrag #2
K
katko
Member
Beiträge
5
Punkte Reaktionen
0
// Thats the css code in my editor!


@grid-padding: 10px;
@mobile-break: 600px;

@keyframes up-in {
from {opacity: 0; bottom: 0%;}
to {opacity: 1; bottom: 50%;}
}

.fill {
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
}

body,
html {
height: 100%;
min-width: 100%;
min-height: 100%;
margin: 0;
padding: 0;
overflow: hidden;

font-family: 'Raleway', sans-serif;
}

.flex-row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
}

.container {
.flex-row;
width: 100%;
min-height: 100%;
height: 100%;
overflow: auto;
background-color: white;
position: relative;

&.no-scroll {
overflow: hidden;
}
}

.page {
width: 80%;
padding: @grid-padding;
background-color: white;
}

@media (max-width: @mobile-break)
{
.page
{
width: 90%;
}
}

.grid {
.flex-row;
.grid-item {
width: 33%;
position: relative;
&:after {
content: '';
display: block;
margin-top: 100%;
}
}

@media (max-width: @mobile-break)
{
.grid-item
{
width: 50%;
}
}
}

.box {
position: absolute;
top: @grid-padding;
bottom: @grid-padding;
left: @grid-padding;
right: @grid-padding;
background-color: white;
background-size: cover;
background-repeat: no-repeat;
background-position: center top;
overflow: hidden;

cursor: pointer;

img
{
width: 100%;
transition: transform 0.6s ease;
}

&.selected {
opacity: 0;
}
&.on-top {
cursor: default;
transition: all 0.4s ease;
box-shadow: 2px 2px 19px -2px rgba(0, 0, 0, 0.44);
}

&.image-out
{
img
{
transform: translateY(-100%);
}
}
}

.content
{
position: absolute;
padding: 20px 40px;
top: 0;
right: 0;
bottom: 0;
left: 0;

opacity: 0;
transition: opacity 0.5s ease;

.show &
{
opacity: 1;
}
}

@media (max-width: @mobile-break)
{
.content
{
padding: 10px 20px;
}
}

.scroller {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow-y: auto;

h1
{
color: white;
width: 100%;
margin-bottom: 30px;
position: absolute;
bottom: 50%;
text-align: center;

animation: up-in 1s ease;
}
}

.top-up.ng-hide-add,
.top-up.ng-hide-remove {
transition: 0s ease top;
}

.top-up.ng-hide-add-active,
.top-up.ng-hide-remove-active {
transition: 0.6s ease top;
}

.top-up.ng-hide-add {
top: 0;
}

.top-up.ng-hide-add.ng-hide-add-active {
top: 100%;
}

.top-up.ng-hide-remove {
top: 100%;
}

.top-up.ng-hide-remove.ng-hide-remove-active {
top: 0
}

.fullscreen-background {
overflow-y: auto;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #333;
transition: top 0.5s ease;
.fill;
&.show {
top: 0;
}
}

.close-button {
position: fixed;
top: 20px;
right: 20px;
color: white;
cursor: pointer;
i {
font-size: 35px;
}
&:hover {
color: #ddd;
}
}
 
  • Need help :) Beitrag #3
basti1012
basti1012
Well-known member
Beiträge
242
Punkte Reaktionen
18
The css code in codepen is written in CSS(less). You need to click the little down arrow and then press compiled css

This is the normal css
Code:
@-webkit-keyframes up-in {
  from {
    opacity: 0;
    bottom: 0%;
  }
  to {
    opacity: 1;
    bottom: 50%;
  }
}
@keyframes up-in {
  from {
    opacity: 0;
    bottom: 0%;
  }
  to {
    opacity: 1;
    bottom: 50%;
  }
}
.fill {
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  background-attachment: fixed;
}
body,
html {
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: "Raleway", sans-serif;
}
.flex-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
}
.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
  width: 100%;
  min-height: 100%;
  height: 100%;
  overflow: auto;
  background-color: white;
  position: relative;
}
.container.no-scroll {
  overflow: hidden;
}
.page {
  width: 80%;
  padding: 10px;
  background-color: white;
}
@media (max-width: 600px) {
  .page {
    width: 90%;
  }
}
.grid {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
}
.grid .grid-item {
  width: 33%;
  position: relative;
}
.grid .grid-item:after {
  content: "";
  display: block;
  margin-top: 100%;
}
@media (max-width: 600px) {
  .grid .grid-item {
    width: 50%;
  }
}
.box {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 10px;
  right: 10px;
  background-color: white;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center top;
  overflow: hidden;
  cursor: pointer;
}
.box img {
  width: 100%;
  transition: transform 0.6s ease;
}
.box.selected {
  opacity: 0;
}
.box.on-top {
  cursor: default;
  transition: all 0.4s ease;
  box-shadow: 2px 2px 19px -2px rgba(0, 0, 0, 0.44);
}
.box.image-out img {
  transform: translateY(-100%);
}
.content {
  position: absolute;
  padding: 20px 40px;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.show .content {
  opacity: 1;
}
@media (max-width: 600px) {
  .content {
    padding: 10px 20px;
  }
}
.scroller {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow-y: auto;
}
.scroller h1 {
  color: white;
  width: 100%;
  margin-bottom: 30px;
  position: absolute;
  bottom: 50%;
  text-align: center;
  -webkit-animation: up-in 1s ease;
          animation: up-in 1s ease;
}
.top-up.ng-hide-add,
.top-up.ng-hide-remove {
  transition: 0s ease top;
}
.top-up.ng-hide-add-active,
.top-up.ng-hide-remove-active {
  transition: 0.6s ease top;
}
.top-up.ng-hide-add {
  top: 0;
}
.top-up.ng-hide-add.ng-hide-add-active {
  top: 100%;
}
.top-up.ng-hide-remove {
  top: 100%;
}
.top-up.ng-hide-remove.ng-hide-remove-active {
  top: 0;
}
.fullscreen-background {
  overflow-y: auto;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #333;
  transition: top 0.5s ease;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  background-attachment: fixed;
}
.fullscreen-background.show {
  top: 0;
}
.close-button {
  position: fixed;
  top: 20px;
  right: 20px;
  color: white;
  cursor: pointer;
}
.close-button i {
  font-size: 35px;
}
.close-button:hover {
  color: #ddd;
}
 
  • Need help :) Beitrag #4
K
katko
Member
Beiträge
5
Punkte Reaktionen
0
Ahh i see, thank u very much.
Done the same with the JS file and fixed all the errors.
Somehow it still doesn't work for me.
I have all these 3 files and i linked them together in the HTML-file like this:

<link rel="stylesheet" href="test.css" type="text/css"/>
<script src="project_switch.js"></script>

With obviously the CSS file named test and the JS file named project_switch.
Is that the right way?
 
  • Need help :) Beitrag #6
basti1012
basti1012
Well-known member
Beiträge
242
Punkte Reaktionen
18
If you click on the little cogs in codeoen, you will see that you still have to integrate further scripts
Code:
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-animate.min.js"></script>

everything together must now look like this. Sorry about my bad english

HTML:
<!doctype html>
<html>
<head>
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Raleway:200" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-animate.min.js"></script>
  <style>
    @-webkit-keyframes up-in {
      from {
        opacity: 0;
        bottom: 0%;
      }
      to {
        opacity: 1;
        bottom: 50%;
      }
    }
    @keyframes up-in {
      from {
        opacity: 0;
        bottom: 0%;
      }
      to {
        opacity: 1;
        bottom: 50%;
      }
    }
    .fill {
      background-repeat: no-repeat;
      background-position: center center;
      background-size: cover;
      background-attachment: fixed;
    }

    body,
    html {
      height: 100%;
      min-width: 100%;
      min-height: 100%;
      margin: 0;
      padding: 0;
      overflow: hidden;
      font-family: "Raleway", sans-serif;
    }

    .flex-row {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-around;
    }

    .container {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-around;
      width: 100%;
      min-height: 100%;
      height: 100%;
      overflow: auto;
      background-color: white;
      position: relative;
    }

    .container.no-scroll {
      overflow: hidden;
    }

    .page {
      width: 80%;
      padding: 10px;
      background-color: white;
    }

    @media (max-width: 600px) {
      .page {
        width: 90%;
      }
    }

    .grid {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-around;
    }

    .grid .grid-item {
      width: 33%;
      position: relative;
    }

    .grid .grid-item:after {
      content: "";
      display: block;
      margin-top: 100%;
    }

    @media (max-width: 600px) {
      .grid .grid-item {
        width: 50%;
      }
    }

    .box {
      position: absolute;
      top: 10px;
      bottom: 10px;
      left: 10px;
      right: 10px;
      background-color: white;
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center top;
      overflow: hidden;
      cursor: pointer;
    }

    .box img {
      width: 100%;
      transition: transform 0.6s ease;
    }

    .box.selected {
      opacity: 0;
    }

    .box.on-top {
      cursor: default;
      transition: all 0.4s ease;
      box-shadow: 2px 2px 19px -2px rgba(0, 0, 0, 0.44);
    }

    .box.image-out img {
      transform: translateY(-100%);
    }

    .content {
      position: absolute;
      padding: 20px 40px;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      opacity: 0;
      transition: opacity 0.5s ease;
    }

    .show .content {
      opacity: 1;
    }

    @media (max-width: 600px) {
      .content {
        padding: 10px 20px;
      }
    }

    .scroller {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      overflow-y: auto;
    }

    .scroller h1 {
      color: white;
      width: 100%;
      margin-bottom: 30px;
      position: absolute;
      bottom: 50%;
      text-align: center;
      -webkit-animation: up-in 1s ease;
      animation: up-in 1s ease;
    }

    .top-up.ng-hide-add,
    .top-up.ng-hide-remove {
      transition: 0s ease top;
    }

    .top-up.ng-hide-add-active,
    .top-up.ng-hide-remove-active {
      transition: 0.6s ease top;
    }

    .top-up.ng-hide-add {
      top: 0;
    }

    .top-up.ng-hide-add.ng-hide-add-active {
      top: 100%;
    }

    .top-up.ng-hide-remove {
      top: 100%;
    }

    .top-up.ng-hide-remove.ng-hide-remove-active {
      top: 0;
    }

    .fullscreen-background {
      overflow-y: auto;
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: #333;
      transition: top 0.5s ease;
      background-repeat: no-repeat;
      background-position: center center;
      background-size: cover;
      background-attachment: fixed;
    }

    .fullscreen-background.show {
      top: 0;
    }

    .close-button {
      position: fixed;
      top: 20px;
      right: 20px;
      color: white;
      cursor: pointer;
    }

    .close-button i {
      font-size: 35px;
    }

    .close-button:hover {
      color: #ddd;
    }
  </style>

</head>
<body>
<div class="container" ng-class="{'no-scroll': selected.length}" ng-app="app" ng-controller="mainCtrl">
  <div class="page">
    <div class="grid">
      <div class="grid-item" ng-repeat="item in boxes">
        <box class="box" item="item" on-select="selectBox" ng-class="{'selected': selected[0].item.name == item.name}"></box>
      </div>
    </div>
  </div>
  <div class="fullscreen-background top-up" ng-show="selected.length" ng-style="{'background-image': 'url(' + selected[0].item.image + ')'}"></div>
  <div class="scroller" ng-show="selected.length">
    <a class="close-button" ng-click="clearSelection()">
      <i class="material-icons">close</i>
    </a>
    <h1>{{selected[0].item.name}}</h1>
    <div big-box ng-repeat="item in selected" class="box on-top" position="item.position" selected="item.item">
      <img ng-src="{{item.item.image}}" alt="" />
      <div class="content">
        <h2>Lorem ipsum dolor</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime laborum perferendis, ullam minus. Illo ad aliquid ab magni, enim nesciunt at consequuntur dolores explicabo nisi. Dolor, reiciendis suscipit alias nemo.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus consequatur, sit saepe reprehenderit nisi dolorem, voluptates amet quos ab assumenda non id accusamus, dicta soluta laboriosam voluptas fuga sint deleniti. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magnam officiis minus tenetur ex molestias qui possimus sit facilis dolorum suscipit. Cumque, aperiam inventore nobis? Veniam voluptatibus sapiente ea, voluptate dolores?</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur dicta ducimus ratione reiciendis officia odit omnis distinctio, eveniet et modi fuga nisi voluptatem nihil aliquam ex pariatur possimus repudiandae vero?</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis, quos ducimus nobis. Necessitatibus provident impedit, neque quia dolores? Quas, architecto id. Iure distinctio, illum eaque at quia assumenda modi saepe. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero soluta quisquam autem quasi ut ex ab modi. Sit soluta dicta incidunt quaerat tenetur fugiat, natus perspiciatis illo. Totam, quo, minus.</p>
      </div>
    </div>

  </div>
</div>
<script>
  var app = angular.module('app', ['ngAnimate'])
  app.controller('mainCtrl', function($scope) {
    $scope.boxes = [{
      name: 'Friends',
      image: 'https://source.unsplash.com/uAgLGG1WBd4/900x900'
    }, {
      name: 'Free',
      image: 'https://source.unsplash.com/Cp-LUHPRpWM/900x900'
    }, {
      name: 'Explore',
      image: 'https://source.unsplash.com/7BjmDICVloE/900x900'
    }, {
      name: 'Vast',
      image: 'https://source.unsplash.com/WLUHO9A_xik/900x900'
    }, {
      name: 'Playful',
      image: 'https://source.unsplash.com/b2-fBVrfx0o/900x900'
    }, {
      name: 'Grand',
      image: 'https://source.unsplash.com/Ixp4YhCKZkI/900x900'
    }, {
      name: 'Mist',
      image: 'https://source.unsplash.com/8BmNurlVR6M/900x900'
    }, {
      name: 'Sea',
      image: 'https://source.unsplash.com/6YqpFWWQsno/900x900'
    }, {
      name: 'Reach',
      image: 'https://source.unsplash.com/zFnk_bTLApo/900x900'
    }, {
      name: 'Awe',
      image: 'https://source.unsplash.com/j4PaE7E2_Ws/900x900'
    }, {
      name: 'Surf',
      image: 'https://source.unsplash.com/uohGiEVhWiQ/900x900'
    }, {
      name: 'Thrill',
      image: 'https://source.unsplash.com/ssrbaKvxaos/900x900'
    }, ];
    $scope.selected = [];
    $scope.selectBox = function(item, position) {
      $scope.selected = [{
        item: item,
        position: position
      }];
      $scope.$apply();
    }
    $scope.clearSelection = function() {
      $scope.selected = [];
    }
  })
  app.directive('box', function() {
    return {
      restrict: 'E',
      scope: {},
      bindToController: {
        onSelect: "=",
        item: "="
      },
      controllerAs: 'box',
      controller: function() {
        var box = this;
        box.goFullscreen = function(e) {
          box.onSelect(box.item, e.target.getBoundingClientRect())
        }
      },
      link: function(scope, element) {
        element.bind('click', scope.box.goFullscreen)
        element.css({
          'background-image': 'url(' + scope.box.item.image + ')'
        })
      }
    }
  })
  app.directive('bigBox', function($timeout) {
    return {
      restrict: 'AE',
      scope: {},
      bindToController: {
        position: "=",
        selected: "=",
        onSelect: "="
      },
      controllerAs: 'box',
      controller: function() {
        var box = this;
      },
      link: function(scope, element) {
        var css = {}
        for (var key in scope.box.position) {
          css[key] = scope.box.position[key] + 'px';
        }
        element.css(css);
        $timeout(function() {
          element.css({
            top: '50%',
            left: '10%'
          })
          element.addClass('image-out');
        }, 200)
        $timeout(function() {
          element.css({
            width: '80%',
            height: '100%'
          })
        }, 500)
        $timeout(function() {
          element.addClass('show');
        }, 800)
      }
    }
  })
</script>
</body>

</html>
 
  • Need help :) Beitrag #7
K
katko
Member
Beiträge
5
Punkte Reaktionen
0
Haha kein Problem, können auch auf Deutsch schreiben.
Danke schonmal!
Funktioniert es bei dir wenn du diese Datei im Browser aufrufen würdest?
habe noch
<script src="https://codepen.io/steveg3003/pen/zBVakw.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
hinzugefügt, aber rührt sich leider nix.
Sorry haha bin noch sehr neu darin.
 
Thema:

Need help :)

Oben Unten